summaryrefslogtreecommitdiff
path: root/src/cat/LegacyLuaAPI.cpp
diff options
context:
space:
mode:
authormniip <mniip@mniip.com>2013-05-02 21:09:13 (GMT)
committer mniip <mniip@mniip.com>2013-05-02 21:09:13 (GMT)
commitd8023d21cd8240d4aedc9d63a0e1cd056b15c919 (patch)
tree60d2835a8fb776632898a3e0523e43b1098a5147 /src/cat/LegacyLuaAPI.cpp
parent29496cb6d3418eaed63f78a6624458ecf410bfc3 (diff)
downloadpowder-d8023d21cd8240d4aedc9d63a0e1cd056b15c919.zip
powder-d8023d21cd8240d4aedc9d63a0e1cd056b15c919.tar.gz
better luacon_geterror
Diffstat (limited to 'src/cat/LegacyLuaAPI.cpp')
-rw-r--r--src/cat/LegacyLuaAPI.cpp51
1 files changed, 25 insertions, 26 deletions
diff --git a/src/cat/LegacyLuaAPI.cpp b/src/cat/LegacyLuaAPI.cpp
index 4abd041..45b7f96 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";
+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 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);