mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-11 07:11:39 +00:00
foreachmap.lua: add shortcut for quickly finding certain sectors/walls/sprites.
git-svn-id: https://svn.eduke32.com/eduke32@3023 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
7e05f5884c
commit
c04f7cbb4c
1 changed files with 19 additions and 3 deletions
|
@ -23,11 +23,15 @@ local os = require "os"
|
|||
if (#arg < 1) then
|
||||
local wr = function(s) io.stdout:write(s) end
|
||||
wr("Usage: ./foreachmap <module[.lua]> [init args...] <filename.map> ...\n")
|
||||
wr(" ./foreachmap -e\"some_lua_code ...\" <filename.map> ...\n\n")
|
||||
wr(" ./foreachmap -e\"some_lua_code ...\" <filename.map> ...\n")
|
||||
wr(" ./foreachmap -e\"[sector|wall|sprite]: <condition on .<field>>\" <fn.map> ...\n\n")
|
||||
wr("In the second form, the code is run as body of a function(map, fn)\n")
|
||||
wr("and num{sectors,walls,sprites} and {sector,wall,sprite} do not\n")
|
||||
wr("need to be qualified with the \"map.\" prefix.\n\n")
|
||||
wr("Example: ./foreachmap.lua -e\"if map.numbunches==1 then print(fn) end\" ~/.eduke32/*.map\n\n")
|
||||
wr("need to be qualified with the \"map.\" prefix.\n")
|
||||
wr("The third form is a shortcut for quickly finding sectors/walls/sprites\n")
|
||||
wr("satisfying a certain condition (see example below)\n\n")
|
||||
wr("Examples: ./foreachmap.lua -e\"if map.numbunches==1 then print(fn) end\" ~/.eduke32/*.map\n")
|
||||
wr(" ./foreachmap.lua -e\"sprite: .picnum==10 and .lotag==2563\" *.map\n\n")
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -36,6 +40,18 @@ local modname = string.gsub(arg[1], "%.lua$", "")
|
|||
local mod
|
||||
if (modname:sub(1,2) == "-e") then
|
||||
local body = modname:sub(3)
|
||||
|
||||
-- sector/wall/sprite finder shortcut
|
||||
local b, e, what = body:find("^([a-z]+):")
|
||||
if (what) then
|
||||
body = body:sub(e+1)
|
||||
body = body:gsub("%.[a-z]+", what.."[i]%0")
|
||||
body =
|
||||
"for i=0,num"..what.."s-1 do"..
|
||||
" if ("..body..") then print(fn..': '..i) end "..
|
||||
"end"
|
||||
end
|
||||
|
||||
local successfunc, errmsg = loadstring(
|
||||
"local numsectors, numwalls, numsprites\n"
|
||||
.."local sector, wall, sprite\n"
|
||||
|
|
Loading…
Reference in a new issue