Lua tweaks: a couple of functions, dfusion tweak, backtrace metadata.

develop
Alexander Gavrilov 2012-04-01 12:50:56 +04:00
parent 73cf822a13
commit a9a6fbd8b5
3 changed files with 31 additions and 3 deletions

@ -189,7 +189,7 @@ bool DFHack::Lua::Require(color_ostream &out, lua_State *state,
static bool load_with_env(color_ostream &out, lua_State *state, const std::string &code, int eidx)
{
if (luaL_loadstring(state, code.c_str()) != LUA_OK)
if (luaL_loadbuffer(state, code.data(), code.size(), "=(interactive)") != LUA_OK)
{
report_error(out, state);
return false;

@ -1,5 +1,29 @@
-- Common startup file for all dfhack plugins with lua support
-- The global dfhack table is already created by C++ init code.
-- The global dfhack table is already created by C++ init
-- code. Feed it back to the require() mechanism.
function mkmodule(module,env)
local pkg = package.loaded[module]
if pkg == nil then
pkg = {}
else
if type(pkg) ~= 'table' then
error("Not a table in package.loaded["..module.."]")
end
end
setmetatable(pkg, { __index = (env or _G) })
return pkg
end
function reload(module)
if type(package.loaded[module]) ~= 'table' then
error("Module not loaded: "..module)
end
local path,err = package.searchpath(module,package.path)
if not path then
error(err)
end
dofile(path)
end
-- Feed the table back to the require() mechanism.
return dfhack

@ -1,3 +1,7 @@
Console.print = dfhack.print
Console.println = dfhack.println
Console.printerr = dfhack.printerr
function err(msg) --make local maybe...
print(msg)
print(debug.traceback())