summaryrefslogtreecommitdiff
path: root/src/scriptapi.cpp
diff options
context:
space:
mode:
authorsapier <sapier at gmx dot net>2012-01-15 20:09:55 +0100
committersapier <sapier at gmx dot net>2012-01-15 20:09:55 +0100
commit285f5a025975207f9251165e82dadb50d4744991 (patch)
treea4102bff145e67b86ce6904801e6a7b8d911511c /src/scriptapi.cpp
parent71186974fa30b68292b66bb43124040957edfc31 (diff)
downloadminetest-285f5a025975207f9251165e82dadb50d4744991.tar.xz
added lua command get_nodes_inside_radius
Diffstat (limited to 'src/scriptapi.cpp')
-rw-r--r--src/scriptapi.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp
index d14634276..39a3b06ff 100644
--- a/src/scriptapi.cpp
+++ b/src/scriptapi.cpp
@@ -2602,6 +2602,35 @@ private:
return 1;
}
+ // EnvRef:get_objects_inside_radius(pos, radius)
+ static int l_get_nodes_inside_radius(lua_State *L)
+ {
+ // Get the table insert function
+ lua_getglobal(L, "table");
+ lua_getfield(L, -1, "insert");
+ int table_insert = lua_gettop(L);
+ // Get environemnt
+ EnvRef *o = checkobject(L, 1);
+ ServerEnvironment *env = o->m_env;
+ if(env == NULL) return 0;
+ // Do it
+ v3s16 pos = read_v3s16(L, 2);
+ float radius = luaL_checknumber(L, 3);// * BS;
+ core::list<MapNode> nodes = env->getNodesInsideRadius(pos, radius);
+ lua_newtable(L);
+ int table = lua_gettop(L);
+ for(core::list<MapNode>::Iterator
+ i = nodes.begin(); i != nodes.end(); i++){
+ // Insert object reference into table
+ lua_pushvalue(L, table_insert);
+ lua_pushvalue(L, table);
+ pushnode(L, *i, env->getGameDef()->ndef());
+ if(lua_pcall(L, 2, 0, 0))
+ script_error(L, "error: %s", lua_tostring(L, -1));
+ }
+ return 1;
+ }
+
static int gc_object(lua_State *L) {
EnvRef *o = *(EnvRef **)(lua_touserdata(L, 1));
delete o;
@@ -2679,6 +2708,7 @@ const luaL_reg EnvRef::methods[] = {
method(EnvRef, get_meta),
method(EnvRef, get_player_by_name),
method(EnvRef, get_objects_inside_radius),
+ method(EnvRef, get_nodes_inside_radius),
{0,0}
};