diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-03-03 22:58:34 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-03-03 23:22:43 +0100 |
commit | f08b62e1a0b9719bb03fd0db89353f69f0680def (patch) | |
tree | acdec3cb220802c36169df43f4c9dabd1b6bdc88 /src/scripting/lua.cpp | |
parent | 72881e2a713a29fc7eaaa1d7159129e0e4f9867f (diff) | |
download | manaserv-f08b62e1a0b9719bb03fd0db89353f69f0680def.tar.gz manaserv-f08b62e1a0b9719bb03fd0db89353f69f0680def.tar.bz2 manaserv-f08b62e1a0b9719bb03fd0db89353f69f0680def.tar.xz manaserv-f08b62e1a0b9719bb03fd0db89353f69f0680def.zip |
Removed the last direct call to global script function
The ScriptAction of the TriggerArea (which can be created by
mana.trigger_create) was still using a named global function for its
callback. Now it also uses a reference to a script function.
Since it was the last occurrence of a call to a global script function,
I've also removed the Script::prepare(std::string) overload.
Reviewed-by: Erik Schilling
Mantis-issue: 299
Diffstat (limited to 'src/scripting/lua.cpp')
-rw-r--r-- | src/scripting/lua.cpp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 59e7d2e1..9bd35ddd 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -1681,10 +1681,10 @@ static int chr_set_quest(lua_State *s) } /** - * mana.trigger_create(int x, int y, int width, int height, - * string function, int id) - * Creates a trigger area. Whenever an actor enters this area, a Lua function - * is called. + * mana.trigger_create(int x, int y, int width, int height, function, int id, + * boolean once) + * Creates a trigger area. Whenever an actor enters this area, the given Lua + * function is called. */ static int trigger_create(lua_State *s) { @@ -1692,8 +1692,7 @@ static int trigger_create(lua_State *s) const int y = luaL_checkint(s, 2); const int width = luaL_checkint(s, 3); const int height = luaL_checkint(s, 4); - //TODO: Turn the function string to a lua function pointer - const char *function = luaL_checkstring(s, 5); + luaL_checktype(s, 5, LUA_TFUNCTION); const int id = luaL_checkint(s, 6); if (!lua_isboolean(s, 7)) @@ -1703,12 +1702,6 @@ static int trigger_create(lua_State *s) } Script *script = getScript(s); - bool once = lua_toboolean(s, 7); - - LOG_INFO("Created script trigger at " << x << ":" << y - << " (" << width << "x" << height << ") function: " << function - << " (" << id << ")"); - MapComposite *m = script->getMap(); if (!m) @@ -1717,10 +1710,20 @@ static int trigger_create(lua_State *s) return 0; } + const bool once = lua_toboolean(s, 7); + + Script::Ref function; + lua_pushvalue(s, 5); + script->assignCallback(function); + lua_pop(s, 1); + ScriptAction *action = new ScriptAction(script, function, id); Rectangle r = { x, y, width, height }; TriggerArea *area = new TriggerArea(m, r, action, once); + LOG_INFO("Created script trigger at " << x << "," << y + << " (" << width << "x" << height << ") id: " << id); + bool ret = GameState::insert(area); lua_pushboolean(s, ret); return 1; |