lua: Add automatic return and = handling in console.
This commit is contained in:
parent
e647cd00c6
commit
9c049271e7
1 changed files with 17 additions and 6 deletions
|
@ -1481,15 +1481,26 @@ static void inject_string(script_info *info, char const *line)
|
||||||
{
|
{
|
||||||
lua_State *L = info->state;
|
lua_State *L = info->state;
|
||||||
int base, top;
|
int base, top;
|
||||||
|
char *ret_line;
|
||||||
|
|
||||||
|
if(line[0] == '=')
|
||||||
|
line++;
|
||||||
|
ret_line = g_strconcat("return ", line, NULL);
|
||||||
|
|
||||||
lua_rawgeti(L, LUA_REGISTRYINDEX, info->traceback);
|
lua_rawgeti(L, LUA_REGISTRYINDEX, info->traceback);
|
||||||
base = lua_gettop(L);
|
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(luaL_loadbuffer(L, line, strlen(line), "@interpreter"))
|
||||||
{
|
{
|
||||||
hexchat_printf(ph, "Lua syntax error: %s", luaL_optstring(L, -1, ""));
|
hexchat_printf(ph, "Lua syntax error: %s", luaL_optstring(L, -1, ""));
|
||||||
lua_pop(L, 2);
|
lua_pop(L, 2);
|
||||||
|
g_free(ret_line);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
g_free(ret_line);
|
||||||
info->status |= STATUS_ACTIVE;
|
info->status |= STATUS_ACTIVE;
|
||||||
if(lua_pcall(L, 0, LUA_MULTRET, base))
|
if(lua_pcall(L, 0, LUA_MULTRET, base))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue