From 1e6b7a30b7232dce7b8240441bed04912e06f666 Mon Sep 17 00:00:00 2001 From: Erik Schilling Date: Sat, 8 Oct 2011 11:19:44 +0200 Subject: Added script bindings for reading map objects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit map_get_objects([string filter]): returns all object of the current map optionally filtered by type. map_get_object_property(handle object, string key): returns the value of the property of the object. map_get_object_bounds(handle object): returns x, y, width, height of an object. map_get_object_name(handle object): returns name of an object. map_get_object_type(handle object): returns type of an object. Mantis-issue: 397 Reviewed-by: Thorbjørn Lindeijer --- src/scripting/lua.cpp | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) (limited to 'src/scripting/lua.cpp') diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 7213bd09..16781937 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -2102,6 +2102,132 @@ static int get_distance(lua_State *s) return 1; } +/** + * mana.map_get_objects(): table of all objects + * mana.map_get_objects(string type): table of all objects of type + * Gets the objects of a map. + */ +static int map_get_objects(lua_State *s) +{ + const bool filtered = (lua_gettop(s) == 1); + std::string filter; + if (filtered) + filter = luaL_checkstring(s, 1); + + lua_pushlightuserdata(s, (void *)®istryKey); + lua_gettable(s, LUA_REGISTRYINDEX); + Script *t = static_cast