From 015d9180fb6e9024229dfeded26cf9c3553e36d8 Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Thu, 9 Aug 2007 17:52:59 +0000 Subject: Converted NPC class to scripting engine. --- src/scripting/lua.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/scripting/lua.cpp') diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index b22d287..099e326 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -47,7 +47,7 @@ class LuaScript: public Script void push(int); - void push(Character *); + void push(Thing *); int execute(); @@ -90,8 +90,11 @@ void LuaScript::push(int v) ++nbArgs; } -void LuaScript::push(Character *v) +void LuaScript::push(Thing *v) { + assert(nbArgs >= 0); + lua_pushlightuserdata(mState, v); + ++nbArgs; } int LuaScript::execute() @@ -99,13 +102,15 @@ int LuaScript::execute() assert(nbArgs >= 0); int res = lua_pcall(mState, nbArgs, 1, 0); nbArgs = -1; - if (res || !lua_isnumber(mState, 0)) + if (res || !lua_isnumber(mState, 1)) { - LOG_ERROR("Failure while calling Lua function: " - << lua_tostring(mState, 0)); + LOG_WARN("Failure while calling Lua function: error=" << res + << ", type=" << lua_typename(mState, lua_type(mState, 1)) + << ", message=" << lua_tostring(mState, 1)); + lua_pop(mState, 1); return 0; } - res = lua_tointeger(mState, 0); + res = lua_tointeger(mState, 1); lua_pop(mState, 1); return res; } -- cgit