forked from your-land-mirror/cmd_eval
add goir() and oir()
This commit is contained in:
parent
ed80ef004d
commit
a5a6ba6630
11
README.md
11
README.md
@ -141,3 +141,14 @@ already existed.
|
||||
#### `dir()` and `keys()`
|
||||
|
||||
List keys of the table (useful for exploring data structures, without flooding your chat).
|
||||
|
||||
#### `get_objects_inside_radius()` shortcuts: `goir()` and `oir()`
|
||||
|
||||
`goir(radius)` returns a list of objects around you
|
||||
`oir(radius)` returns an iterator of objects around you
|
||||
|
||||
```
|
||||
> goir(100) -- return a list of objects within 100 units around you
|
||||
|
||||
> for v in oir(100) do print((v:get_luaentity() or {}).name) end
|
||||
```
|
||||
|
26
init.lua
26
init.lua
@ -116,6 +116,32 @@ local function create_shared_environment(player_name)
|
||||
end
|
||||
end,
|
||||
--dump = repl_dump,
|
||||
goir = function(radius)
|
||||
local me = core.get_player_by_name(player_name)
|
||||
if me then
|
||||
local objs = core.get_objects_inside_radius(me:get_pos(), radius)
|
||||
return objs
|
||||
else
|
||||
return {}
|
||||
end
|
||||
end,
|
||||
oir = function(radius)
|
||||
local me = core.get_player_by_name(player_name)
|
||||
if me then
|
||||
local objs = core.get_objects_inside_radius(me:get_pos(), radius)
|
||||
local nextkey, v
|
||||
--local i = 1
|
||||
return function()
|
||||
-- FIXME skip invalid objects here?
|
||||
nextkey, v = next(objs, nextkey)
|
||||
return v
|
||||
-- i = i + 1
|
||||
-- return objs[i]
|
||||
end
|
||||
else
|
||||
return function() return nil end
|
||||
end
|
||||
end,
|
||||
},
|
||||
{
|
||||
__index = function(self, key)
|
||||
|
Loading…
Reference in New Issue
Block a user