From c0c208d4c29ff49f940e8a6c54adb26cc4e5eba3 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Thu, 1 Mar 2012 21:54:04 +0100 Subject: Converted functions called by LuaScript to callbacks This includes the quest reply, post reply, death notification and remove notification. Also, Script::Ref was changed from a typedef to a small class, automating initialization and making the check for validness clearer. Reviewed-by: Erik Schilling --- src/scripting/lua.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/scripting/lua.cpp') diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 7a94ce24..33bd9eb9 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -97,6 +97,34 @@ static int on_character_death_accept(lua_State *s) return 0; } +static int on_npc_quest_reply(lua_State *s) +{ + luaL_checktype(s, 1, LUA_TFUNCTION); + LuaScript::setQuestReplyCallback(getScript(s)); + return 0; +} + +static int on_npc_post_reply(lua_State *s) +{ + luaL_checktype(s, 1, LUA_TFUNCTION); + LuaScript::setPostReplyCallback(getScript(s)); + return 0; +} + +static int on_being_death(lua_State *s) +{ + luaL_checktype(s, 1, LUA_TFUNCTION); + LuaScript::setDeathNotificationCallback(getScript(s)); + return 0; +} + +static int on_being_remove(lua_State *s) +{ + luaL_checktype(s, 1, LUA_TFUNCTION); + LuaScript::setRemoveNotificationCallback(getScript(s)); + return 0; +} + /** * mana.npc_message(NPC*, Character*, string): void * Callback for sending a NPC_MESSAGE. @@ -2590,6 +2618,10 @@ LuaScript::LuaScript(): static luaL_Reg const callbacks[] = { { "on_character_death", &on_character_death }, { "on_character_death_accept", &on_character_death_accept }, + { "on_npc_quest_reply", &on_npc_quest_reply }, + { "on_npc_post_reply", &on_npc_post_reply }, + { "on_being_death", &on_being_death }, + { "on_being_remove", &on_being_remove }, { "npc_create", &npc_create }, { "npc_message", &npc_message }, { "npc_choice", &npc_choice }, -- cgit v1.2.3-70-g09d2