From d4ee26fb6b05c07c84f61799bcb2cba81873b873 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Tue, 3 Jan 2012 22:47:30 +0100 Subject: Random small fixes linked to lua c++ scripting functions. Reviewed-by: Ablu --- src/scripting/lua.cpp | 49 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) (limited to 'src/scripting/lua.cpp') diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 6eba4353..2b92e193 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -470,6 +470,7 @@ static int chr_inv_count(lua_State *s) { LOG_WARN("chr_inv_count called with id 0! " "Currency is now handled through attributes!"); + lua_pushinteger(s, 0); } else { @@ -623,6 +624,7 @@ static int chr_get_level(lua_State *s) { raiseScriptError(s, "chr_get_level " "called for nonexistent character."); + return 0; } lua_pushinteger(s, ch->getLevel()); @@ -1108,9 +1110,10 @@ static int being_get_name(lua_State *s) if (being) { lua_pushstring(s, being->getName().c_str()); + return 1; } - return 1; + return 0; } /** @@ -1124,9 +1127,10 @@ static int being_get_action(lua_State *s) if (being) { lua_pushinteger(s, being->getAction()); + return 1; } - return 1; + return 0; } /** @@ -1158,9 +1162,10 @@ static int being_get_direction(lua_State *s) if (being) { lua_pushinteger(s, being->getDirection()); + return 1; } - return 1; + return 0; } /** @@ -1187,10 +1192,16 @@ static int being_set_direction(lua_State *s) */ static int posX(lua_State *s) { - int x = getBeing(s, 1)->getPosition().x; - lua_pushinteger(s, x); + Being *being = getBeing(s, 1); - return 1; + if (being) + { + int x = being->getPosition().x; + lua_pushinteger(s, x); + return 1; + } + + return 0; } /** @@ -1199,10 +1210,16 @@ static int posX(lua_State *s) */ static int posY(lua_State *s) { - int y = getBeing(s, 1)->getPosition().y; - lua_pushinteger(s, y); + Being *being = getBeing(s, 1); - return 1; + if (being) + { + int y = being->getPosition().y; + lua_pushinteger(s, y); + return 1; + } + + return 0; } /** @@ -1358,6 +1375,7 @@ static int chr_get_quest(lua_State *s) { raiseScriptError(s, "chr_get_quest " "called for nonexistent character."); + return 0; } const char *m = luaL_checkstring(s, 2); @@ -2128,7 +2146,13 @@ static int get_map_id(lua_State *s) lua_pushlightuserdata(s, (void *)®istryKey); lua_gettable(s, LUA_REGISTRYINDEX); Script *t = static_cast