From 9c049271e79764c7ca32a55072c7de11237ae26b Mon Sep 17 00:00:00 2001 From: mniip Date: Wed, 13 Jul 2016 13:02:40 +0300 Subject: lua: Add automatic return and = handling in console. --- plugins/lua/lua.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/plugins/lua/lua.c b/plugins/lua/lua.c index b6f2465d..6f3fc27f 100644 --- a/plugins/lua/lua.c +++ b/plugins/lua/lua.c @@ -831,7 +831,7 @@ static inline int list_marshal(lua_State *L, const char *key, hexchat_list *list } if (list != NULL) { - time_t tm = hexchat_list_time(ph, list, key); + time_t tm = hexchat_list_time(ph, list, key); if(tm != -1) { lua_pushinteger(L, tm); @@ -845,7 +845,7 @@ static inline int list_marshal(lua_State *L, const char *key, hexchat_list *list static int api_hexchat_props_meta_index(lua_State *L) { - char const *key = luaL_checkstring(L, 2); + char const *key = luaL_checkstring(L, 2); return list_marshal(L, key, NULL); } @@ -1481,15 +1481,26 @@ static void inject_string(script_info *info, char const *line) { lua_State *L = info->state; int base, top; + char *ret_line; + + if(line[0] == '=') + line++; + ret_line = g_strconcat("return ", line, NULL); lua_rawgeti(L, LUA_REGISTRYINDEX, info->traceback); base = lua_gettop(L); - if(luaL_loadbuffer(L, line, strlen(line), "@interpreter")) + if(luaL_loadbuffer(L, ret_line, strlen(ret_line), "@interpreter")) { - hexchat_printf(ph, "Lua syntax error: %s", luaL_optstring(L, -1, "")); - lua_pop(L, 2); - return; + lua_pop(L, 1); + if(luaL_loadbuffer(L, line, strlen(line), "@interpreter")) + { + hexchat_printf(ph, "Lua syntax error: %s", luaL_optstring(L, -1, "")); + lua_pop(L, 2); + g_free(ret_line); + return; + } } + g_free(ret_line); info->status |= STATUS_ACTIVE; if(lua_pcall(L, 0, LUA_MULTRET, base)) { -- cgit 1.4.1