summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@googlemail.com>2011-08-01 14:42:40 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-08-03 20:03:11 +0200
commit17e800c6edd889c6b7b4826adb944ab32a45f1b2 (patch)
tree51911c7b31851b52512b7449e6490a757c569ea9 /src
parent8d20b4cab34cf91786e3bf00afcc24e17f742a46 (diff)
downloadmanaserv-17e800c6edd889c6b7b4826adb944ab32a45f1b2.tar.gz
manaserv-17e800c6edd889c6b7b4826adb944ab32a45f1b2.tar.bz2
manaserv-17e800c6edd889c6b7b4826adb944ab32a45f1b2.tar.xz
manaserv-17e800c6edd889c6b7b4826adb944ab32a45f1b2.zip
Added get_map_property lua function.
mana.get_map_prpoperty(string) can now be used to read a property from a map file. String is the property name. Resolves: Mana-Mantis #353. Reviewed-by: Bertram.
Diffstat (limited to 'src')
-rw-r--r--src/scripting/lua.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index d461bf44..553c8593 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -1789,6 +1789,29 @@ static int get_map_id(lua_State *s)
}
/**
+ * Returns the value of a map property
+ */
+static int get_map_property(lua_State *s)
+{
+ const char *property = luaL_checkstring(s, 1);
+ lua_pushlightuserdata(s, (void *)&registryKey);
+ lua_gettable(s, LUA_REGISTRYINDEX);
+ Script *t = static_cast<Script *>(lua_touserdata(s, -1));
+ MapComposite *m = t->getMap();
+ if (!m)
+ {
+ raiseScriptError(s, "get_map_property called outside a map.");
+ return 0;
+ }
+ Map *map = m->getMap();
+ std::string value = map->getProperty(property);
+ const char *v = &value[0];
+
+ lua_pushstring(s, v);
+ return 1;
+}
+
+/**
* Creates an item stack on the floor
* mana.drop_item(x, y, id[, number])
*/
@@ -1960,6 +1983,7 @@ LuaScript::LuaScript():
{ "chr_shake_screen", &chr_shake_screen },
{ "test_tableget", &test_tableget },
{ "get_map_id", &get_map_id },
+ { "get_map_property", &get_map_property },
{ "item_drop", &item_drop },
{ "npc_ask_integer", &npc_ask_integer },
{ "npc_end", &npc_end },