diff options
| author | Alexander Gavrilov | 2012-04-03 13:13:44 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-04-03 13:13:44 +0400 |
| commit | 444377f9db0e5443433468cc13904bed5b343d40 (patch) | |
| tree | 5cbaacb75085613e654280a9a26d7279af2091bc /library/LuaTools.cpp | |
| parent | 59d1971df163ffeb97873b9290e3fc6864d5bf50 (diff) | |
| download | dfhack-444377f9db0e5443433468cc13904bed5b343d40.tar.gz dfhack-444377f9db0e5443433468cc13904bed5b343d40.tar.bz2 dfhack-444377f9db0e5443433468cc13904bed5b343d40.tar.xz | |
Finish documenting the DFHack core lua api existing so far.
Diffstat (limited to 'library/LuaTools.cpp')
| -rw-r--r-- | library/LuaTools.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/library/LuaTools.cpp b/library/LuaTools.cpp index f81396f9..1477b16d 100644 --- a/library/LuaTools.cpp +++ b/library/LuaTools.cpp @@ -240,6 +240,8 @@ bool DFHack::Lua::InterpreterLoop(color_ostream &out, lua_State *state, // Make a proxy global environment. lua_newtable(state); + int base = lua_gettop(state); + lua_newtable(state); if (env) lua_pushvalue(state, env); @@ -249,7 +251,6 @@ bool DFHack::Lua::InterpreterLoop(color_ostream &out, lua_State *state, lua_setmetatable(state, -2); // Main interactive loop - int base = lua_gettop(state); int vcnt = 1; string curline; string prompt_str = "[" + string(prompt) + "]# "; @@ -324,8 +325,20 @@ bool DFHack::Lua::InterpreterLoop(color_ostream &out, lua_State *state, static int lua_dfhack_interpreter(lua_State *state) { color_ostream *pstream = Lua::GetOutput(state); + if (!pstream) - luaL_error(state, "Cannot use dfhack.interpreter() without output."); + { + lua_pushnil(state); + lua_pushstring(state, "no output stream"); + return 2; + } + + if (!pstream->is_console()) + { + lua_pushnil(state); + lua_pushstring(state, "not an interactive console"); + return 2; + } int argc = lua_gettop(state); @@ -459,6 +472,8 @@ static PersistentDataItem get_persistent(lua_State *state) static int dfhack_persistent_get(lua_State *state) { + CoreSuspender suspend; + auto ref = get_persistent(state); return read_persistent(state, ref, !lua_istable(state, 1)); @@ -466,6 +481,8 @@ static int dfhack_persistent_get(lua_State *state) static int dfhack_persistent_delete(lua_State *state) { + CoreSuspender suspend; + auto ref = get_persistent(state); bool ok = Core::getInstance().getWorld()->DeletePersistentData(ref); @@ -476,6 +493,8 @@ static int dfhack_persistent_delete(lua_State *state) static int dfhack_persistent_get_all(lua_State *state) { + CoreSuspender suspend; + const char *str = luaL_checkstring(state, 1); bool prefix = (lua_gettop(state)>=2 ? lua_toboolean(state,2) : false); @@ -501,6 +520,8 @@ static int dfhack_persistent_get_all(lua_State *state) static int dfhack_persistent_save(lua_State *state) { + CoreSuspender suspend; + lua_settop(state, 2); luaL_checktype(state, 1, LUA_TTABLE); bool add = lua_toboolean(state, 2); |
