|
|
@ -399,9 +399,13 @@ function Script:get_flags()
|
|
|
|
local f = io.open(self.path)
|
|
|
|
local f = io.open(self.path)
|
|
|
|
local contents = f:read('*all')
|
|
|
|
local contents = f:read('*all')
|
|
|
|
f:close()
|
|
|
|
f:close()
|
|
|
|
for line in contents:gmatch('--@([^\n]+)') do
|
|
|
|
for line in contents:gmatch('%-%-@([^\n]+)') do
|
|
|
|
local chunk = load(line, self.path, 't', self._flags)
|
|
|
|
local chunk = load(line, self.path, 't', self._flags)
|
|
|
|
if chunk then chunk() end
|
|
|
|
if chunk then
|
|
|
|
|
|
|
|
chunk()
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
dfhack.printerr('Parse error: ' .. line)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return self._flags
|
|
|
|
return self._flags
|
|
|
@ -434,7 +438,7 @@ function dfhack.findScript(name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local valid_script_flags = {
|
|
|
|
local valid_script_flags = {
|
|
|
|
enable = {required = true},
|
|
|
|
enable = {required = true, error = 'Does not recognize enable/disable commands'},
|
|
|
|
enable_state = {required = false},
|
|
|
|
enable_state = {required = false},
|
|
|
|
module = {required = true, error = 'Cannot be used as a module'},
|
|
|
|
module = {required = true, error = 'Cannot be used as a module'},
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -444,9 +448,10 @@ function dfhack.run_script(name,...)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function dfhack.enable_script(name, state)
|
|
|
|
function dfhack.enable_script(name, state)
|
|
|
|
local res = dfhack.pcall(dfhack.run_script_with_env, nil, name, {enable=true, enable_state=state})
|
|
|
|
local res, err = dfhack.pcall(dfhack.run_script_with_env, nil, name, {enable=true, enable_state=state})
|
|
|
|
if not res then
|
|
|
|
if not res then
|
|
|
|
qerror('Cannot ' .. (state and 'enable' or 'disable') .. ' Lua script: ' .. name)
|
|
|
|
dfhack.printerr(err.message)
|
|
|
|
|
|
|
|
qerror(('Cannot %s Lua script: %s'):format(state and 'enable' or 'disable', name))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|