2011-07-16 08:22:45 -06:00
|
|
|
#include <dfhack/Core.h>
|
|
|
|
#include <dfhack/Console.h>
|
|
|
|
#include <dfhack/Export.h>
|
|
|
|
#include <dfhack/PluginManager.h>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
2011-07-16 11:43:57 -06:00
|
|
|
|
2011-07-16 13:08:58 -06:00
|
|
|
#include "luamain.h"
|
|
|
|
#include "lua_Console.h"
|
2011-07-16 10:29:46 -06:00
|
|
|
|
2011-07-16 08:22:45 -06:00
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using namespace DFHack;
|
|
|
|
|
2011-07-16 13:08:58 -06:00
|
|
|
static SDL::Mutex* mymutex=0;
|
2011-07-16 10:29:46 -06:00
|
|
|
|
2011-07-16 08:22:45 -06:00
|
|
|
DFhackCExport command_result dfusion (Core * c, vector <string> & parameters);
|
|
|
|
|
|
|
|
|
|
|
|
DFhackCExport const char * plugin_name ( void )
|
|
|
|
{
|
|
|
|
return "dfusion";
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
|
|
|
commands.clear();
|
2011-07-16 13:08:58 -06:00
|
|
|
//maybe remake it to run automaticaly
|
|
|
|
lua::RegisterConsole(lua::glua::Get(),&c->con);
|
|
|
|
|
|
|
|
commands.push_back(PluginCommand("dfusion","Init dfusion system.",dfusion));
|
2011-07-16 11:43:57 -06:00
|
|
|
mymutex=SDL_CreateMutex();
|
2011-07-16 08:22:45 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown ( Core * c )
|
|
|
|
{
|
2011-07-16 10:29:46 -06:00
|
|
|
|
2011-07-16 08:22:45 -06:00
|
|
|
// shutdown stuff
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_onupdate ( Core * c )
|
|
|
|
{
|
2011-07-16 13:08:58 -06:00
|
|
|
/*if(timering == true) //TODO maybe reuse this to make it run less often.
|
2011-07-16 08:22:45 -06:00
|
|
|
{
|
|
|
|
uint64_t time2 = GetTimeMs64();
|
|
|
|
uint64_t delta = time2-timeLast;
|
|
|
|
timeLast = time2;
|
|
|
|
c->con.print("Time delta = %d ms\n", delta);
|
|
|
|
}
|
|
|
|
return CR_OK;*/
|
2011-07-16 13:08:58 -06:00
|
|
|
SDL_mutexP(mymutex);
|
2011-07-16 11:43:57 -06:00
|
|
|
lua::state s=lua::glua::Get();
|
|
|
|
s.getglobal("OnTick");
|
|
|
|
if(s.is<lua::function>())
|
|
|
|
{
|
2011-07-16 13:23:44 -06:00
|
|
|
try{
|
|
|
|
s.pcall();
|
|
|
|
}
|
|
|
|
catch(lua::exception &e)
|
|
|
|
{
|
|
|
|
c->con.printerr("Error OnTick:%s\n",e.what());
|
|
|
|
c->con.msleep(1000);
|
|
|
|
}
|
2011-07-16 11:43:57 -06:00
|
|
|
}
|
|
|
|
s.settop(0);
|
|
|
|
SDL_mutexV(mymutex);
|
2011-07-16 08:22:45 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2011-07-16 09:34:24 -06:00
|
|
|
|
2011-07-16 08:22:45 -06:00
|
|
|
DFhackCExport command_result dfusion (Core * c, vector <string> & parameters)
|
|
|
|
{
|
|
|
|
// do stuff
|
2011-07-16 09:34:24 -06:00
|
|
|
Console &con=c->con;
|
2011-07-16 11:43:57 -06:00
|
|
|
SDL_mutexP(mymutex);
|
2011-07-16 13:08:58 -06:00
|
|
|
lua::state s=lua::glua::Get();
|
|
|
|
|
2011-07-16 10:29:46 -06:00
|
|
|
try{
|
2011-07-16 13:08:58 -06:00
|
|
|
s.loadfile("dfusion/init.lua"); //load script
|
|
|
|
s.pcall(0,0);// run it
|
2011-07-16 10:29:46 -06:00
|
|
|
}
|
|
|
|
catch(lua::exception &e)
|
|
|
|
{
|
2011-07-16 11:43:57 -06:00
|
|
|
con.printerr("Error:%s\n",e.what());
|
2011-07-16 10:29:46 -06:00
|
|
|
}
|
2011-07-16 13:08:58 -06:00
|
|
|
s.settop(0);// clean up
|
2011-07-16 11:43:57 -06:00
|
|
|
SDL_mutexV(mymutex);
|
2011-07-16 08:22:45 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|