lua: Force 'return' when = is present

This commit is contained in:
mniip 2016-07-14 17:04:58 +03:00
parent 9c049271e7
commit 9ca1606e2a
1 changed files with 7 additions and 2 deletions

View File

@ -1482,17 +1482,22 @@ static void inject_string(script_info *info, char const *line)
lua_State *L = info->state;
int base, top;
char *ret_line;
gboolean force_ret = FALSE;
if(line[0] == '=')
{
line++;
force_ret = TRUE;
}
ret_line = g_strconcat("return ", line, NULL);
lua_rawgeti(L, LUA_REGISTRYINDEX, info->traceback);
base = lua_gettop(L);
if(luaL_loadbuffer(L, ret_line, strlen(ret_line), "@interpreter"))
{
lua_pop(L, 1);
if(luaL_loadbuffer(L, line, strlen(line), "@interpreter"))
if(!force_ret)
lua_pop(L, 1);
if(force_ret || luaL_loadbuffer(L, line, strlen(line), "@interpreter"))
{
hexchat_printf(ph, "Lua syntax error: %s", luaL_optstring(L, -1, ""));
lua_pop(L, 2);