|
|
@ -31,8 +31,10 @@ uint64_t timeLast=0;
|
|
|
|
|
|
|
|
|
|
|
|
DFHACK_PLUGIN("dfusion")
|
|
|
|
DFHACK_PLUGIN("dfusion")
|
|
|
|
|
|
|
|
|
|
|
|
command_result dfusion (Core * c, vector <string> & parameters);
|
|
|
|
command_result dfusion (color_ostream &out, std::vector <std::string> ¶meters);
|
|
|
|
command_result lua_run (Core * c, vector <string> & parameters);
|
|
|
|
command_result dfuse (color_ostream &out, std::vector <std::string> ¶meters);
|
|
|
|
|
|
|
|
command_result lua_run (color_ostream &out, std::vector <std::string> ¶meters);
|
|
|
|
|
|
|
|
command_result lua_run_file (color_ostream &out, std::vector <std::string> ¶meters);
|
|
|
|
|
|
|
|
|
|
|
|
DFhackCExport const char * plugin_name ( void )
|
|
|
|
DFhackCExport const char * plugin_name ( void )
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -43,7 +45,7 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lua::state st=lua::glua::Get();
|
|
|
|
lua::state st=lua::glua::Get();
|
|
|
|
//maybe remake it to run automaticaly
|
|
|
|
//maybe remake it to run automaticaly
|
|
|
|
lua::RegisterConsole(st,&c->con);
|
|
|
|
lua::RegisterConsole(st);
|
|
|
|
lua::RegisterProcess(st,c->p);
|
|
|
|
lua::RegisterProcess(st,c->p);
|
|
|
|
lua::RegisterHexsearch(st);
|
|
|
|
lua::RegisterHexsearch(st);
|
|
|
|
lua::RegisterMisc(st);
|
|
|
|
lua::RegisterMisc(st);
|
|
|
@ -59,9 +61,10 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand>
|
|
|
|
st.setglobal("WINDOWS");
|
|
|
|
st.setglobal("WINDOWS");
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
commands.push_back(PluginCommand("dfusion","Init dfusion system. Use 'dfusion init' to run dfusion in init mode (not interactive).",dfusion));
|
|
|
|
commands.push_back(PluginCommand("dfusion","Run dfusion system (interactive i.e. can input further commands).",dfusion,true));
|
|
|
|
commands.push_back(PluginCommand("lua", "Run interactive interpreter. Use 'lua <filename>' to run <filename> instead.",lua_run));
|
|
|
|
commands.push_back(PluginCommand("dfuse","Init dfusion system (not interactive).",dfuse,false));
|
|
|
|
|
|
|
|
commands.push_back(PluginCommand("lua", "Run interactive interpreter. Use 'lua <filename>' to run <filename> instead.",lua_run,true));
|
|
|
|
|
|
|
|
commands.push_back(PluginCommand("runlua", "Run non-interactive interpreter. Use 'runlua <filename>' to run <filename>.",lua_run_file,false));
|
|
|
|
mymutex=new tthread::mutex;
|
|
|
|
mymutex=new tthread::mutex;
|
|
|
|
return CR_OK;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -93,9 +96,9 @@ DFhackCExport command_result plugin_onupdate_DISABLED ( Core * c )
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(lua::exception &e)
|
|
|
|
catch(lua::exception &e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
c->con.printerr("Error OnTick:%s\n",e.what());
|
|
|
|
c->getConsole().printerr("Error OnTick:%s\n",e.what());
|
|
|
|
c->con.printerr("%s\n",lua::DebugDump(lua::glua::Get()).c_str());
|
|
|
|
c->getConsole().printerr("%s\n",lua::DebugDump(lua::glua::Get()).c_str());
|
|
|
|
c->con.msleep(1000);
|
|
|
|
c->getConsole().msleep(1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.settop(0);
|
|
|
|
s.settop(0);
|
|
|
@ -103,13 +106,15 @@ DFhackCExport command_result plugin_onupdate_DISABLED ( Core * c )
|
|
|
|
return CR_OK;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InterpreterLoop(Core* c)
|
|
|
|
void InterpreterLoop(color_ostream &out)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Console &con=c->con;
|
|
|
|
|
|
|
|
DFHack::CommandHistory hist;
|
|
|
|
DFHack::CommandHistory hist;
|
|
|
|
lua::state s=lua::glua::Get();
|
|
|
|
lua::state s=lua::glua::Get();
|
|
|
|
string curline;
|
|
|
|
string curline;
|
|
|
|
con.print("Type quit to exit interactive mode\n");
|
|
|
|
out.print("Type quit to exit interactive mode\n");
|
|
|
|
|
|
|
|
assert(out.is_console());
|
|
|
|
|
|
|
|
Console &con = static_cast<Console&>(out);
|
|
|
|
con.lineedit(">>",curline,hist);
|
|
|
|
con.lineedit(">>",curline,hist);
|
|
|
|
|
|
|
|
|
|
|
|
while (curline!="quit") {
|
|
|
|
while (curline!="quit") {
|
|
|
@ -122,18 +127,27 @@ void InterpreterLoop(Core* c)
|
|
|
|
catch(lua::exception &e)
|
|
|
|
catch(lua::exception &e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
con.printerr("Error:%s\n",e.what());
|
|
|
|
con.printerr("Error:%s\n",e.what());
|
|
|
|
c->con.printerr("%s\n",lua::DebugDump(lua::glua::Get()).c_str());
|
|
|
|
con.printerr("%s\n",lua::DebugDump(lua::glua::Get()).c_str());
|
|
|
|
s.settop(0);
|
|
|
|
s.settop(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
con.lineedit(">>",curline,hist);
|
|
|
|
con.lineedit(">>",curline,hist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.settop(0);
|
|
|
|
s.settop(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
command_result lua_run (Core * c, vector <string> & parameters)
|
|
|
|
command_result lua_run_file (color_ostream &out, std::vector <std::string> ¶meters)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(parameters.size()==0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
out.printerr("runlua without file to run!");
|
|
|
|
|
|
|
|
return CR_FAILURE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return lua_run(out,parameters);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
command_result lua_run (color_ostream &out, std::vector <std::string> ¶meters)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Console &con=c->con;
|
|
|
|
|
|
|
|
mymutex->lock();
|
|
|
|
mymutex->lock();
|
|
|
|
lua::state s=lua::glua::Get();
|
|
|
|
lua::state s=lua::glua::Get();
|
|
|
|
|
|
|
|
lua::SetConsole(s,out);
|
|
|
|
if(parameters.size()>0)
|
|
|
|
if(parameters.size()>0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try{
|
|
|
|
try{
|
|
|
@ -142,23 +156,21 @@ command_result lua_run (Core * c, vector <string> & parameters)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(lua::exception &e)
|
|
|
|
catch(lua::exception &e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
con.printerr("Error:%s\n",e.what());
|
|
|
|
out.printerr("Error:%s\n",e.what());
|
|
|
|
c->con.printerr("%s\n",lua::DebugDump(lua::glua::Get()).c_str());
|
|
|
|
out.printerr("%s\n",lua::DebugDump(lua::glua::Get()).c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
InterpreterLoop(c);
|
|
|
|
InterpreterLoop(out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.settop(0);// clean up
|
|
|
|
s.settop(0);// clean up
|
|
|
|
mymutex->unlock();
|
|
|
|
mymutex->unlock();
|
|
|
|
return CR_OK;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void RunDfusion(void *p)
|
|
|
|
void RunDfusion(color_ostream &out)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Console &con=static_cast<Core*>(p)->con;
|
|
|
|
|
|
|
|
mymutex->lock();
|
|
|
|
mymutex->lock();
|
|
|
|
|
|
|
|
|
|
|
|
lua::state s=lua::glua::Get();
|
|
|
|
lua::state s=lua::glua::Get();
|
|
|
|
try{
|
|
|
|
try{
|
|
|
|
s.getglobal("err");
|
|
|
|
s.getglobal("err");
|
|
|
@ -169,26 +181,27 @@ void RunDfusion(void *p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(lua::exception &e)
|
|
|
|
catch(lua::exception &e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
con.printerr("Error:%s\n",e.what());
|
|
|
|
out.printerr("Error:%s\n",e.what());
|
|
|
|
con.printerr("%s\n",lua::DebugDump(lua::glua::Get()).c_str());
|
|
|
|
out.printerr("%s\n",lua::DebugDump(lua::glua::Get()).c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.settop(0);// clean up
|
|
|
|
s.settop(0);// clean up
|
|
|
|
mymutex->unlock();
|
|
|
|
mymutex->unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
command_result dfusion (Core * c, vector <string> & parameters)
|
|
|
|
command_result dfuse(color_ostream &out, std::vector <std::string> ¶meters)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(parameters[0]=="init")
|
|
|
|
lua::state s=lua::glua::Get();
|
|
|
|
{
|
|
|
|
lua::SetConsole(s,out);
|
|
|
|
lua::state s=lua::glua::Get();
|
|
|
|
s.push(1);
|
|
|
|
s.push(1);
|
|
|
|
s.setglobal("INIT");
|
|
|
|
s.setglobal("INIT");
|
|
|
|
RunDfusion(out);
|
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
else
|
|
|
|
}
|
|
|
|
{
|
|
|
|
command_result dfusion (color_ostream &out, std::vector <std::string> ¶meters)
|
|
|
|
lua::state s=lua::glua::Get();
|
|
|
|
{
|
|
|
|
s.push();
|
|
|
|
lua::state s=lua::glua::Get();
|
|
|
|
s.setglobal("INIT");
|
|
|
|
lua::SetConsole(s,out);
|
|
|
|
}
|
|
|
|
s.push();
|
|
|
|
RunDfusion(c);
|
|
|
|
s.setglobal("INIT");
|
|
|
|
|
|
|
|
RunDfusion(out);
|
|
|
|
return CR_OK;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|