summary refs log tree commit diff stats
path: root/plugins
diff options
context:
space:
mode:
authormniip <mniip@mniip.com>2016-07-13 13:02:40 +0300
committermniip <mniip@mniip.com>2016-07-14 01:43:26 +0300
commit9c049271e79764c7ca32a55072c7de11237ae26b (patch)
treedc25137bb9a35a228cc58d6180b929c10067010d /plugins
parente647cd00c610bc0da803923845e92451f66917be (diff)
lua: Add automatic return and = handling in console.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/lua/lua.c23
1 files 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))
 	{