Running OK with luaconsole.cpp
This commit is contained in:
@@ -60,8 +60,8 @@ void LuaConsole::add(std::string line) {
|
|||||||
state_ = STATE_SYNTAX;
|
state_ = STATE_SYNTAX;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
state_ = STATE_COMPLETE;
|
|
||||||
syntax_ = "";
|
syntax_ = "";
|
||||||
|
state_ = STATE_COMPLETE;
|
||||||
}
|
}
|
||||||
lua_settop(lua_state_, top);
|
lua_settop(lua_state_, top);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ void LuaStack::register_all_userdata(lua_State *L) {
|
|||||||
LS.rawset(LuaRegistry, lud, tab);
|
LS.rawset(LuaRegistry, lud, tab);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
LS.result();
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaFunctionReg::LuaFunctionReg(const char *m, const char *n, lua_CFunction f) {
|
LuaFunctionReg::LuaFunctionReg(const char *m, const char *n, lua_CFunction f) {
|
||||||
|
|||||||
@@ -55,51 +55,45 @@ static int report(lua_State *L, int status)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int docall(lua_State *L, int narg, int nret)
|
static void doexp(lua_State *L, const std::string &exp)
|
||||||
{
|
{
|
||||||
|
int status = luaL_loadbuffer(L, exp.c_str(), exp.size(), "=stdin");
|
||||||
|
assert(status == LUA_OK);
|
||||||
|
globalL = L;
|
||||||
signal(SIGINT, laction);
|
signal(SIGINT, laction);
|
||||||
int status = traceback_pcall(L, narg, nret);
|
status = traceback_pcall(L, 0, LUA_MULTRET);
|
||||||
signal(SIGINT, SIG_DFL);
|
signal(SIGINT, SIG_DFL);
|
||||||
/* force a complete garbage collection in case of errors */
|
if (status != LUA_OK) {
|
||||||
if (status != LUA_OK)
|
report(L, status);
|
||||||
lua_gc(L, LUA_GCCOLLECT, 0);
|
lua_gc(L, LUA_GCCOLLECT, 0);
|
||||||
return status;
|
}
|
||||||
|
if (status == LUA_OK && lua_gettop(L) > 0) {
|
||||||
|
lua_getglobal(L, "pprint");
|
||||||
|
if (lua_isnil(L, -1)) {
|
||||||
|
lua_pop(L, 1);
|
||||||
|
lua_getglobal(L, "print");
|
||||||
|
}
|
||||||
|
lua_insert(L, 1);
|
||||||
|
if (lua_pcall(L, lua_gettop(L) - 1, 0, 0) != 0) {
|
||||||
|
l_message(
|
||||||
|
lua_pushfstring(L, "error calling 'print' (%s)",
|
||||||
|
lua_tostring(L, -1)));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dotty(lua_State *L)
|
void TextGame::run()
|
||||||
{
|
{
|
||||||
LuaConsole console;
|
LuaConsole console;
|
||||||
int status;
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
console.add_stdin();
|
||||||
switch (console.state()) {
|
switch (console.state()) {
|
||||||
case LuaConsole::STATE_INCOMPLETE:
|
case LuaConsole::STATE_INCOMPLETE:
|
||||||
console.add_stdin();
|
|
||||||
break;
|
break;
|
||||||
case LuaConsole::STATE_COMPLETE: {
|
case LuaConsole::STATE_COMPLETE:
|
||||||
const std::string &exp = console.expression();
|
doexp(viewer_.get_lua_state(), console.expression());
|
||||||
status = luaL_loadbuffer(L, exp.c_str(), exp.size(), "=stdin");
|
|
||||||
assert(status == LUA_OK);
|
|
||||||
status = docall(L, 0, LUA_MULTRET);
|
|
||||||
report(L, status);
|
|
||||||
if (status == LUA_OK && lua_gettop(L) > 0) {
|
|
||||||
// any result to print?
|
|
||||||
lua_getglobal(L, "pprint");
|
|
||||||
if (lua_isnil(L, -1)) {
|
|
||||||
lua_pop(L, 1);
|
|
||||||
lua_getglobal(L, "print");
|
|
||||||
}
|
|
||||||
lua_insert(L, 1);
|
|
||||||
if (lua_pcall(L, lua_gettop(L) - 1, 0, 0) != 0)
|
|
||||||
{
|
|
||||||
l_message(
|
|
||||||
lua_pushfstring(L, "error calling 'print' (%s)",
|
|
||||||
lua_tostring(L, -1)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
console.clear();
|
console.clear();
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case LuaConsole::STATE_SLASHCOMMAND:
|
case LuaConsole::STATE_SLASHCOMMAND:
|
||||||
std::cerr << "Slash commands not supported yet." << std::endl;
|
std::cerr << "Slash commands not supported yet." << std::endl;
|
||||||
console.clear();
|
console.clear();
|
||||||
@@ -112,8 +106,3 @@ static void dotty(lua_State *L)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextGame::run()
|
|
||||||
{
|
|
||||||
dotty(viewer_.get_lua_state());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ World::World() {
|
|||||||
// Initialize the SourceDB
|
// Initialize the SourceDB
|
||||||
source_db_.initialize(lua_state_);
|
source_db_.initialize(lua_state_);
|
||||||
source_db_.rebuild();
|
source_db_.rebuild();
|
||||||
|
|
||||||
|
LS.result();
|
||||||
|
assert (lua_gettop(lua_state_) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tangible::be_a_player() {
|
void Tangible::be_a_player() {
|
||||||
|
|||||||
Reference in New Issue
Block a user