lua-users home
lua-l archive

Re: Multiple Lua Script Files

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It's a bit different whether you load the script by -lmyscript or as myscript.lua. Here's some code I use in Hamster, to come around this. Perhaps it will help?
local main= "main" -- main script
-- Finding subscripts:
--
local LUA_PATH= rawget(_G,"package") and package.path
 or os.getenv("LUA_PATH")
if not LUA_PATH then
 error "LUA_PATH environment variable not set."
end
rawset( _G, "MY_PATH", false )
for pat in string.gfind( LUA_PATH, "[^;]+" ) do
 local try= string.gsub( pat, "?", "hamster" )
 local fh= io.open(try,"r")
 if fh then
 fh:close()
 MY_PATH= string.gsub(try,"hamster%.lua","")
 break
 end
end
assert(MY_PATH)
--
-- Actual application code:
--
local m= dofile( MY_PATH..main..".lua" )
return m
Chris Gurtler kirjoitti 14.1.2006 kello 5.09:
Thank you,
Do you have an example of this?
CHU Run-min wrote:
IMHO, you should make a state variable which indicates the current
executed script file.

AltStyle によって変換されたページ (->オリジナル) /