diff options
| author | jacob1 <jfu614@gmail.com> | 2013-05-03 19:09:35 (GMT) |
|---|---|---|
| committer | jacob1 <jfu614@gmail.com> | 2013-05-03 19:09:35 (GMT) |
| commit | e95e8e26bf0d11e33ef5f723abcd64348c0847fc (patch) | |
| tree | ebf58c4831fe4c7b434bea6cdb9d8541e9ecf9ae /src/cat/LegacyLuaAPI.cpp | |
| parent | 2eaed9c9d478292f18d8a6aea9d2c9c869b26911 (diff) | |
| parent | 4cd12e8561b71ce32598d791ddedf5f1aef9203c (diff) | |
| download | powder-e95e8e26bf0d11e33ef5f723abcd64348c0847fc.zip powder-e95e8e26bf0d11e33ef5f723abcd64348c0847fc.tar.gz | |
Merge pull request #132 from mniip/lua2
Some lua fixes
Diffstat (limited to 'src/cat/LegacyLuaAPI.cpp')
| -rw-r--r-- | src/cat/LegacyLuaAPI.cpp | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/src/cat/LegacyLuaAPI.cpp b/src/cat/LegacyLuaAPI.cpp index 75b6780..2166b14 100644 --- a/src/cat/LegacyLuaAPI.cpp +++ b/src/cat/LegacyLuaAPI.cpp @@ -664,12 +664,32 @@ void luacon_hook(lua_State * l, lua_Debug * ar) } } -char *luacon_geterror(){ - char *error = (char*)lua_tostring(luacon_ci->l, -1); - if(error==NULL || !error[0]){ - error = "failed to execute"; +int luaL_tostring (lua_State *L, int n) { + luaL_checkany(L, n); + switch (lua_type(L, n)) { + case LUA_TNUMBER: + lua_pushstring(L, lua_tostring(L, n)); + break; + case LUA_TSTRING: + lua_pushvalue(L, n); + break; + case LUA_TBOOLEAN: + lua_pushstring(L, (lua_toboolean(L, n) ? "true" : "false")); + break; + case LUA_TNIL: + lua_pushliteral(L, "nil"); + break; + default: + lua_pushfstring(L, "%s: %p", luaL_typename(L, n), lua_topointer(L, n)); + break; } - return error; + return 1; +} +char *luacon_geterror(){ + luaL_tostring(luacon_ci->l, -1); + char* err = (char*)luaL_optstring(luacon_ci->l, -1, "failed to execute"); + lua_pop(luacon_ci->l, 1); + return err; } /*void luacon_close(){ lua_close(l); @@ -923,27 +943,6 @@ int luatpt_setconsole(lua_State* l) luacon_controller->HideConsole(); return 0; } -static int luaL_tostring (lua_State *L, int n) { - luaL_checkany(L, n); - switch (lua_type(L, n)) { - case LUA_TNUMBER: - lua_pushstring(L, lua_tostring(L, n)); - break; - case LUA_TSTRING: - lua_pushvalue(L, n); - break; - case LUA_TBOOLEAN: - lua_pushstring(L, (lua_toboolean(L, n) ? "true" : "false")); - break; - case LUA_TNIL: - lua_pushliteral(L, "nil"); - break; - default: - lua_pushfstring(L, "%s: %p", luaL_typename(L, n), lua_topointer(L, n)); - break; - } - return 1; -} int luatpt_log(lua_State* l) { int args = lua_gettop(l); @@ -958,7 +957,11 @@ int luatpt_log(lua_State* l) lua_pop(l, 2); } if((*luacon_currentCommand)) - (*luacon_lastError) = text; + { + if(luacon_lastError->length()) + *luacon_lastError += "; "; + *luacon_lastError += text; + } else luacon_ci->Log(CommandInterface::LogNotice, text.c_str()); return 0; |
