Added simple readme, fixed sdl_threads and moved to tinythreads (mutex for lua engine). Other small fixes

Signed-off-by: Warmist <Warmist@gmail.com>
develop
Warmist 2011-07-27 23:10:20 +03:00
parent 2a95a4edf2
commit d262986740
5 changed files with 64 additions and 9 deletions

@ -2,6 +2,7 @@ find_package(Lua51 QUIET)
if(LUA51_FOUND) if(LUA51_FOUND)
include_directories(${LUA_INCLUDE_DIR} include) include_directories(${LUA_INCLUDE_DIR} include)
include_directories("${dfhack_SOURCE_DIR}/library/depends/tthread")
FILE(GLOB DFUSION_CPPS src/*.c*) FILE(GLOB DFUSION_CPPS src/*.c*)
set( set(
DFUSION_CPPS_ALL DFUSION_CPPS_ALL

@ -6,6 +6,10 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include "tinythread.h"
#include "luamain.h" #include "luamain.h"
#include "lua_Console.h" #include "lua_Console.h"
#include "functioncall.h" #include "functioncall.h"
@ -14,7 +18,7 @@ using std::vector;
using std::string; using std::string;
using namespace DFHack; using namespace DFHack;
static SDL::Mutex* mymutex=0; static tthread::mutex* mymutex=0;
DFhackCExport command_result dfusion (Core * c, vector <string> & parameters); DFhackCExport command_result dfusion (Core * c, vector <string> & parameters);
DFhackCExport command_result lua_run (Core * c, vector <string> & parameters); DFhackCExport command_result lua_run (Core * c, vector <string> & parameters);
@ -37,7 +41,7 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand>
commands.push_back(PluginCommand("lua", "Run interactive interpreter.\ commands.push_back(PluginCommand("lua", "Run interactive interpreter.\
\n Options: <filename> = run <filename> instead",lua_run)); \n Options: <filename> = run <filename> instead",lua_run));
mymutex=SDL_CreateMutex(); mymutex=new tthread::mutex;
return CR_OK; return CR_OK;
} }
@ -45,6 +49,7 @@ DFhackCExport command_result plugin_shutdown ( Core * c )
{ {
// shutdown stuff // shutdown stuff
delete mymutex;
return CR_OK; return CR_OK;
} }
@ -58,7 +63,7 @@ DFhackCExport command_result plugin_onupdate ( Core * c )
c->con.print("Time delta = %d ms\n", delta); c->con.print("Time delta = %d ms\n", delta);
} }
return CR_OK;*/ return CR_OK;*/
SDL_mutexP(mymutex); mymutex->lock();
lua::state s=lua::glua::Get(); lua::state s=lua::glua::Get();
s.getglobal("OnTick"); s.getglobal("OnTick");
if(s.is<lua::function>()) if(s.is<lua::function>())
@ -73,7 +78,7 @@ DFhackCExport command_result plugin_onupdate ( Core * c )
} }
} }
s.settop(0); s.settop(0);
SDL_mutexV(mymutex); mymutex->unlock();
return CR_OK; return CR_OK;
} }
@ -81,7 +86,7 @@ DFhackCExport command_result plugin_onupdate ( Core * c )
DFhackCExport command_result lua_run (Core * c, vector <string> & parameters) DFhackCExport command_result lua_run (Core * c, vector <string> & parameters)
{ {
Console &con=c->con; Console &con=c->con;
SDL_mutexP(mymutex); mymutex->lock();
lua::state s=lua::glua::Get(); lua::state s=lua::glua::Get();
if(parameters.size()>0) if(parameters.size()>0)
{ {
@ -99,15 +104,14 @@ DFhackCExport command_result lua_run (Core * c, vector <string> & parameters)
//TODO interpreter... //TODO interpreter...
} }
s.settop(0);// clean up s.settop(0);// clean up
SDL_mutexV(mymutex); mymutex->unlock();
return CR_OK; return CR_OK;
} }
DFhackCExport command_result dfusion (Core * c, vector <string> & parameters) DFhackCExport command_result dfusion (Core * c, vector <string> & parameters)
{ {
Console &con=c->con; Console &con=c->con;
con.print("%x\n",c->p->getBase()); mymutex->lock();
SDL_mutexP(mymutex);
lua::state s=lua::glua::Get(); lua::state s=lua::glua::Get();
try{ try{
@ -119,6 +123,6 @@ DFhackCExport command_result dfusion (Core * c, vector <string> & parameters)
con.printerr("Error:%s\n",e.what()); con.printerr("Error:%s\n",e.what());
} }
s.settop(0);// clean up s.settop(0);// clean up
SDL_mutexV(mymutex); mymutex->unlock();
return CR_OK; return CR_OK;
} }

@ -0,0 +1,13 @@
#ifndef LUA_OFFSETS_H
#define LUA_OFFSETS_H
#include "luamain.h"
namespace lua
{
void RegisterEngine(lua::state &st);
}
#endif

@ -0,0 +1,19 @@
Dfusion command runs file <df dir>\dfusion\init.lua
Other than std lua commands supported:
* Console.
print(string)
printerr(string)
clear()
gotoxy(x,y)
color(int) //TODO add id's, use numbers upto 16 for now
reset_color()
cursor(true/false)
msleep(int)
get_columns()
get_rows()
lineedit(string) //text input through console
history_add(string) // adds string to console history
Functions searched:
OnTick()
If defined is called each DFHack tick.

@ -0,0 +1,18 @@
#include "lua_Offsets.h"
//TODO make a seperate module with peeks/pokes and page permisions (linux/windows spec)
unsigned char peekb(size_t offset)
{
return *((unsigned char*)(offset));
}
unsigned short peekw(size_t offset)
{
return *((unsigned short*)(offset));
}
unsigned peekd(size_t offset)
{
return *((unsigned*)(offset));
}
void lua::RegisterEngine(lua::state &st)
{
}