From b822dcee52d15d41c4186a250e73b85b16c9dc39 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Sat, 10 Mar 2012 23:38:36 +0100 Subject: Removed the create_npc wrapper and the last two NPC callbacks When creating an NPC, you now provide its optional talk and update functions directly rather than them being stored in a table on the Lua side and then called in response to a global callback. Also fixed an issue with a missing gender parameter to the delayed NPC creation callback used by NPCs defined on the map (found by Erik while reviewing this patch). Reviewed-by: Erik Schilling --- src/scripting/luascript.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/scripting/luascript.cpp') diff --git a/src/scripting/luascript.cpp b/src/scripting/luascript.cpp index e45588b9..36adb912 100644 --- a/src/scripting/luascript.cpp +++ b/src/scripting/luascript.cpp @@ -198,6 +198,15 @@ void LuaScript::assignCallback(Script::Ref &function) function.value = luaL_ref(mRootState, LUA_REGISTRYINDEX); } +void LuaScript::unref(Ref &ref) +{ + if (ref.isValid()) + { + luaL_unref(mRootState, LUA_REGISTRYINDEX, ref.value); + ref.value = -1; + } +} + void LuaScript::load(const char *prog, const char *name) { int res = luaL_loadbuffer(mRootState, prog, std::strlen(prog), name); @@ -262,7 +271,7 @@ void LuaScript::getQuestCallback(Character *q, script->prepareResume(thread); script->push(value); - script->resume(); + q->resumeNpcThread(); } /** @@ -280,7 +289,7 @@ void LuaScript::getPostCallback(Character *q, script->prepareResume(thread); script->push(sender); script->push(letter); - script->resume(); + q->resumeNpcThread(); } -- cgit v1.2.3-70-g09d2