equal
deleted
inserted
replaced
1 |
1 |
2 /* Copyright 2009,2010 Myhailo Danylenko |
2 /* Copyright 2009-2012 Myhailo Danylenko |
3 * Copyright 2011 Mikael Berthe |
3 * Copyright 2011 Mikael Berthe |
4 |
4 |
5 This file is part of mcabber-lua. |
5 This file is part of mcabber-lua. |
6 |
6 |
7 mcabber-lua is free software: you can redistribute it and/or modify |
7 mcabber-lua is free software: you can redistribute it and/or modify |
8 it under the terms of the GNU General Public License as published by |
8 it under the terms of the GNU General Public License as published by |
161 /// A: string (filename, without ".lua") |
161 /// A: string (filename, without ".lua") |
162 /// R: string (error message, optional) |
162 /// R: string (error message, optional) |
163 static int lua_global_dopath (lua_State *L) |
163 static int lua_global_dopath (lua_State *L) |
164 { |
164 { |
165 const char *name = luaL_checkstring (L, 1); |
165 const char *name = luaL_checkstring (L, 1); |
166 size_t size = lua_objlen (L, 1); |
166 size_t size = lua_rawlen (L, 1); |
167 char *path; |
167 char *path; |
168 int ret = 0; |
168 int ret = 0; |
169 if (size > 4 && !strncmp (name + size - 4, ".lua", 4)) |
169 if (size > 4 && !strncmp (name + size - 4, ".lua", 4)) |
170 path = mcabber_config_filename (name); |
170 path = mcabber_config_filename (name); |
171 else { |
171 else { |
487 |
487 |
488 // expects table on top |
488 // expects table on top |
489 static void lua_rosterlist_callback (gpointer buddy, lua_State *L) |
489 static void lua_rosterlist_callback (gpointer buddy, lua_State *L) |
490 { |
490 { |
491 char *jid = from_utf8 (buddy_getjid (buddy)); |
491 char *jid = from_utf8 (buddy_getjid (buddy)); |
492 lua_pushnumber (L, lua_objlen (L, -1) + 1); |
492 lua_pushnumber (L, lua_rawlen (L, -1) + 1); |
493 lua_pushstring (L, jid); |
493 lua_pushstring (L, jid); |
494 lua_settable (L, -3); |
494 lua_settable (L, -3); |
495 g_free (jid); |
495 g_free (jid); |
496 } |
496 } |
497 |
497 |
1169 static void lua_command_init (lua_State *L) |
1169 static void lua_command_init (lua_State *L) |
1170 { |
1170 { |
1171 luaL_newmetatable (L, "mcabber.command"); |
1171 luaL_newmetatable (L, "mcabber.command"); |
1172 lua_pushvalue (L, -1); |
1172 lua_pushvalue (L, -1); |
1173 lua_setfield (L, -2, "__index"); |
1173 lua_setfield (L, -2, "__index"); |
1174 luaL_register (L, NULL, lua_mcabber_command_reg_m); |
1174 luaL_setfuncs (L, lua_mcabber_command_reg_m, 0); |
1175 lua_pop (L, 1); |
1175 lua_pop (L, 1); |
1176 } |
1176 } |
1177 |
1177 |
1178 // TIMER |
1178 // TIMER |
1179 |
1179 |
1558 static void lua_hook_init (lua_State *L) |
1558 static void lua_hook_init (lua_State *L) |
1559 { |
1559 { |
1560 luaL_newmetatable (L, "mcabber.hook"); |
1560 luaL_newmetatable (L, "mcabber.hook"); |
1561 lua_pushvalue (L, -1); |
1561 lua_pushvalue (L, -1); |
1562 lua_setfield (L, -2, "__index"); |
1562 lua_setfield (L, -2, "__index"); |
1563 luaL_register (L, NULL, lua_mcabber_hook_reg_m); |
1563 luaL_setfuncs (L, lua_mcabber_hook_reg_m, 0); |
1564 lua_pop (L, 1); |
1564 lua_pop (L, 1); |
1565 } |
1565 } |
1566 |
1566 |
1567 // OPTION GUARDS |
1567 // OPTION GUARDS |
1568 |
1568 |
1778 |
1778 |
1779 void mlua_init (void) |
1779 void mlua_init (void) |
1780 { |
1780 { |
1781 luaL_openlibs (lua); |
1781 luaL_openlibs (lua); |
1782 |
1782 |
1783 luaL_register (lua, "main", lua_reg_main); |
1783 lua_newtable(lua); |
1784 lua_pop (lua, 1); // XXX |
1784 luaL_setfuncs (lua, lua_reg_main, 0); |
|
1785 lua_setglobal (lua, "main"); |
1785 lua_register (lua, "dopath", lua_global_dopath); |
1786 lua_register (lua, "dopath", lua_global_dopath); |
1786 lua_register (lua, "print", lua_global_print ); |
1787 lua_register (lua, "print", lua_global_print ); |
1787 |
1788 |
1788 { |
1789 { |
1789 #ifdef MCABBER_API_HAVE_COMPL_FLAGS |
1790 #ifdef MCABBER_API_HAVE_COMPL_FLAGS |