From 031709fc8f63bd6fa2399361bbce96667b767e36 Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Thu, 9 Aug 2007 21:24:56 +0000 Subject: Moved creation of testing NPC from C++ to Lua. --- src/scripting/lua.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 8 deletions(-) (limited to 'src/scripting/lua.cpp') diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index f9575b68..9cac37d0 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -33,6 +33,7 @@ extern "C" { #include "game-server/character.hpp" #include "game-server/gamehandler.hpp" #include "game-server/npc.hpp" +#include "game-server/state.hpp" #include "net/messageout.hpp" #include "scripting/script.hpp" #include "utils/logger.h" @@ -62,6 +63,8 @@ class LuaScript: public Script int nbArgs; }; +static char const registryKey = 0; + /* Functions below are unsafe, as they assume the script has passed pointers to objects which have not yet been destroyed. If the script never keeps pointers around, there will be no problem. In order to be safe, the engine @@ -128,6 +131,34 @@ static int LuaMsg_NpcChoice(lua_State *s) return 0; } +/** + * Callback for creating a NPC on the current map with the current script + * (1: int) (2: int) (3: int). + */ +static int LuaObj_CreateNpc(lua_State *s) +{ + if (!lua_isnumber(s, 1) || !lua_isnumber(s, 2) || !lua_isnumber(s, 3)) + { + LOG_WARN("LuaObj_CreateNpc called with incorrect parameters."); + return 0; + } + lua_pushlightuserdata(s, (void *)®istryKey); + lua_gettable(s, LUA_REGISTRYINDEX); + Script *t = static_cast