# HG changeset patch # User Mikael Berthe # Date 1301256210 -7200 # Node ID 3d4f0415c8f8863c4ffb707ab121ba390a7a648f # Parent 15f4c09ffb860c98e0f91c41fa6d53466a4b06c9 Sync with new dev API diff -r 15f4c09ffb86 -r 3d4f0415c8f8 lua.c --- a/lua.c Wed Apr 14 20:27:27 2010 +0300 +++ b/lua.c Sun Mar 27 22:03:30 2011 +0200 @@ -1,5 +1,6 @@ -/* Copyright 2009 Myhailo Danylenko +/* Copyright 2009,2010 Myhailo Danylenko + * Copyright 2011 Mikael Berthe This file is part of mcabber-lua. @@ -62,7 +63,7 @@ static module_info_t info_lua_experimental = { .branch = "experimental", - .api = 27, + .api = 34, .version = PROJECT_VERSION, .description = DESCRIPTION, .requires = NULL, @@ -73,7 +74,7 @@ static module_info_t info_lua_dev = { .branch = "dev", - .api = 13, + .api = 20, .version = PROJECT_VERSION, .description = DESCRIPTION, .requires = NULL, @@ -82,7 +83,7 @@ .next = &info_lua_experimental, }; -module_info_t info_lua = { +module_info_t info_lua_0_10_0 = { .branch = "0.10.0", .api = 1, .version = PROJECT_VERSION, @@ -93,6 +94,21 @@ .next = &info_lua_dev, }; +module_info_t info_lua = { + .branch = "0.10.1", + .api = 1, + .version = PROJECT_VERSION, + .description = DESCRIPTION, + .requires = NULL, + .init = mlua_init, + .uninit = mlua_uninit, + .next = &info_lua_0_10_0, +}; + +#ifdef MCABBER_API_HAVE_CMD_ID +static gpointer lua_cmdid; +#endif + // global lua state object, necessary for uninitialization function static lua_State *lua = NULL; @@ -804,7 +820,7 @@ typedef struct { int cbref; int parse_args; -#ifdef HAVE_CMD_ID +#ifdef MCABBER_API_HAVE_CMD_ID gpointer cmid; #else int nameref; @@ -1059,7 +1075,7 @@ cid = luaL_checkenum (L, 4, lua_completion_type); } } - + cb = lua_newuserdata (L, sizeof (lua_command_t)); luaL_getmetatable (L, "mcabber.command"); lua_setmetatable (L, -2); @@ -1069,7 +1085,7 @@ cb -> selfref = luaL_ref (L, LUA_REGISTRYINDEX); cb -> parse_args = parse; cb -> L = L; -#ifdef HAVE_CMD_ID +#ifdef MCABBER_API_HAVE_CMD_ID cb -> cmid = cmd_add (name, "", cid, 0, (void (*) (char *p)) lua_main_command_handler, cb); #else lua_pushvalue (L, 1); @@ -1082,7 +1098,7 @@ static void lua_mcabber_unregister_command (lua_State *L, lua_command_t *cb) { -#ifdef HAVE_CMD_ID +#ifdef MCABBER_API_HAVE_CMD_ID if (cb -> cmid) cmd_del (cb -> cmid); #else @@ -1119,7 +1135,7 @@ lua_command_t *cb = luaL_checkudata (L, 1, "mcabber.command"); luaL_argcheck (L, cb != NULL, 1, "mcabber command object expected"); lua_mcabber_unregister_command (L, cb); -#ifndef HAVE_CMD_ID +#ifndef MCABBER_API_HAVE_CMD_ID if (cb -> nameref != LUA_NOREF) luaL_unref (L, LUA_REGISTRYINDEX, cb -> nameref); #endif @@ -1747,7 +1763,11 @@ } } +#ifdef MCABBER_API_HAVE_CMD_ID + lua_cmdid = cmd_add ("lua", "Evaluate lua string", 0, 0, (void (*) (char *p)) do_lua, lua); +#else cmd_add ("lua", "Evaluate lua string", 0, 0, (void (*) (char *p)) do_lua, lua); +#endif #ifdef LLM_LOG_HANDLER // FIXME: this should not be here. @@ -1759,7 +1779,7 @@ { char *initfile = expand_filename (settings_opt_get ("lua_init_filename")); - + if (!initfile) scr_log_print (LPRINT_LOGNORM, "lua: Cannot determine config file name"); else { @@ -1853,7 +1873,12 @@ g_slist_free (lua_added_features); lua_added_features = NULL; +#ifdef MCABBER_API_HAVE_CMD_ID + cmd_del (lua_cmdid); + lua_cmdid = NULL; +#else cmd_del ("lua"); +#endif lua_close (lua); lua = NULL;