|
|
|
@ -5,7 +5,8 @@
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
#include <lua.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <luamain.h>
|
|
|
|
|
|
|
|
|
@ -13,7 +14,7 @@ using std::vector;
|
|
|
|
|
using std::string;
|
|
|
|
|
using namespace DFHack;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static SDL::Mutex *mymutex=0;
|
|
|
|
|
|
|
|
|
|
DFhackCExport command_result dfusion (Core * c, vector <string> & parameters);
|
|
|
|
|
|
|
|
|
@ -27,7 +28,7 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand>
|
|
|
|
|
{
|
|
|
|
|
commands.clear();
|
|
|
|
|
commands.push_back(PluginCommand("DFusion","Init dfusion system.",dfusion));
|
|
|
|
|
|
|
|
|
|
mymutex=SDL_CreateMutex();
|
|
|
|
|
return CR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -48,6 +49,15 @@ DFhackCExport command_result plugin_onupdate ( Core * c )
|
|
|
|
|
c->con.print("Time delta = %d ms\n", delta);
|
|
|
|
|
}
|
|
|
|
|
return CR_OK;*/
|
|
|
|
|
SDL_mutexP(mymutex); //TODO: make lua thread safe (somehow)...
|
|
|
|
|
lua::state s=lua::glua::Get();
|
|
|
|
|
s.getglobal("OnTick");
|
|
|
|
|
if(s.is<lua::function>())
|
|
|
|
|
{
|
|
|
|
|
s.pcall();
|
|
|
|
|
}
|
|
|
|
|
s.settop(0);
|
|
|
|
|
SDL_mutexV(mymutex);
|
|
|
|
|
return CR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -56,15 +66,17 @@ DFhackCExport command_result dfusion (Core * c, vector <string> & parameters)
|
|
|
|
|
{
|
|
|
|
|
// do stuff
|
|
|
|
|
Console &con=c->con;
|
|
|
|
|
|
|
|
|
|
SDL_mutexP(mymutex);
|
|
|
|
|
try{
|
|
|
|
|
lua::glua::Get().loadfile("dfusion/init.lua");
|
|
|
|
|
lua::glua::Get().pcall(0,0);
|
|
|
|
|
lua::glua::Get().loadfile("dfusion/init.lua"); //load script
|
|
|
|
|
lua::glua::Get().pcall(0,0);// run it
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch(lua::exception &e)
|
|
|
|
|
{
|
|
|
|
|
con.printerr("Error:%s",e.what());
|
|
|
|
|
con.printerr("Error:%s\n",e.what());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lua::glua::Get().settop(0);// clean up
|
|
|
|
|
SDL_mutexV(mymutex);
|
|
|
|
|
return CR_OK;
|
|
|
|
|
}
|
|
|
|
|