|
|
|
@ -214,17 +214,13 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
|
|
|
|
|
if (!onupdate_active)
|
|
|
|
|
return CR_OK;
|
|
|
|
|
|
|
|
|
|
using namespace df::global;
|
|
|
|
|
|
|
|
|
|
if (cur_year && (*cur_year < onupdate_minyear))
|
|
|
|
|
if (df::global::cur_year && *df::global::cur_year < onupdate_minyear)
|
|
|
|
|
return CR_OK;
|
|
|
|
|
if (cur_year && cur_year_tick && onupdate_minyeartick >= 0 &&
|
|
|
|
|
(*cur_year == onupdate_minyear &&
|
|
|
|
|
*cur_year_tick < onupdate_minyeartick))
|
|
|
|
|
if (df::global::cur_year_tick && onupdate_minyeartick >= 0 &&
|
|
|
|
|
*df::global::cur_year_tick < onupdate_minyeartick)
|
|
|
|
|
return CR_OK;
|
|
|
|
|
if (cur_year && cur_year_tick_advmode && onupdate_minyeartickadv >= 0 &&
|
|
|
|
|
(*cur_year == onupdate_minyear &&
|
|
|
|
|
*cur_year_tick_advmode < onupdate_minyeartickadv))
|
|
|
|
|
if (df::global::cur_year_tick_advmode && onupdate_minyeartickadv >= 0 &&
|
|
|
|
|
*df::global::cur_year_tick_advmode < onupdate_minyeartickadv)
|
|
|
|
|
return CR_OK;
|
|
|
|
|
|
|
|
|
|
return plugin_eval_ruby(out, "DFHack.onupdate");
|
|
|
|
@ -283,21 +279,13 @@ static command_result df_rubyeval(color_ostream &out, std::vector <std::string>
|
|
|
|
|
// - ruby.h with gcc -m32 on linux 64 is broken
|
|
|
|
|
// so we dynamically load libruby with dlopen/LoadLibrary
|
|
|
|
|
// lib path is hardcoded here, and by default downloaded by cmake
|
|
|
|
|
// this code should work with ruby1.9, but ruby1.9 doesn't like running
|
|
|
|
|
// in a dedicated non-main thread, so use ruby1.8 binaries only for now
|
|
|
|
|
|
|
|
|
|
typedef uintptr_t VALUE;
|
|
|
|
|
typedef uintptr_t ID;
|
|
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
|
int major;
|
|
|
|
|
int minor;
|
|
|
|
|
int teeny;
|
|
|
|
|
} libruby_version;
|
|
|
|
|
|
|
|
|
|
static VALUE Qfalse;
|
|
|
|
|
static VALUE Qtrue;
|
|
|
|
|
static VALUE Qnil;
|
|
|
|
|
static VALUE Qfalse = 0;
|
|
|
|
|
static VALUE Qtrue = 2;
|
|
|
|
|
static VALUE Qnil = 4;
|
|
|
|
|
|
|
|
|
|
#define INT2FIX(i) ((VALUE)((((intptr_t)i) << 1) | 1))
|
|
|
|
|
#define FIX2INT(i) (((intptr_t)i) >> 1)
|
|
|
|
@ -345,26 +333,6 @@ static int df_loadruby(void)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *ruby_version = (const char*)LookupPlugin(libruby_handle, "ruby_version");
|
|
|
|
|
if (!ruby_version)
|
|
|
|
|
return 0;
|
|
|
|
|
sscanf(ruby_version, "%d.%d.%d",
|
|
|
|
|
&libruby_version.major, &libruby_version.minor, &libruby_version.teeny);
|
|
|
|
|
|
|
|
|
|
if (libruby_version.major >= 2 && sizeof(VALUE) >= sizeof(double))
|
|
|
|
|
{
|
|
|
|
|
// USE_FLONUM defined on x64
|
|
|
|
|
Qfalse = (VALUE)0;
|
|
|
|
|
Qtrue = (VALUE)0x14;
|
|
|
|
|
Qnil = (VALUE)0x08;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Qfalse = (VALUE)0;
|
|
|
|
|
Qtrue = (VALUE)2;
|
|
|
|
|
Qnil = (VALUE)4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ruby_sysinit is optional (ruby1.9 only)
|
|
|
|
|
ruby_sysinit = (decltype(ruby_sysinit))LookupPlugin(libruby_handle, "ruby_sysinit");
|
|
|
|
|
#define rbloadsym(s) if (!(s = (decltype(s))LookupPlugin(libruby_handle, #s))) return 0
|
|
|
|
@ -465,6 +433,11 @@ static void df_rubythread(void *p)
|
|
|
|
|
r_result = CR_OK;
|
|
|
|
|
r_type = RB_IDLE;
|
|
|
|
|
|
|
|
|
|
// initialize ruby constants (may depend on libruby compilation flags/version)
|
|
|
|
|
Qnil = rb_eval_string_protect("nil", &state);
|
|
|
|
|
Qtrue = rb_eval_string_protect("true", &state);
|
|
|
|
|
Qfalse = rb_eval_string_protect("false", &state);
|
|
|
|
|
|
|
|
|
|
// load the default ruby-level definitions in the background
|
|
|
|
|
state=0;
|
|
|
|
|
rb_eval_string_protect("require './hack/ruby/ruby'", &state);
|
|
|
|
@ -1085,8 +1058,8 @@ static VALUE rb_dfmemory_set_clear(VALUE self, VALUE set)
|
|
|
|
|
|
|
|
|
|
/* call an arbitrary object virtual method */
|
|
|
|
|
#if defined(_WIN32) && !defined(_WIN64)
|
|
|
|
|
__declspec(naked) static int raw_vcall(void *that, void *fptr, unsigned long a0,
|
|
|
|
|
unsigned long a1, unsigned long a2, unsigned long a3, unsigned long a4, unsigned long a5)
|
|
|
|
|
__declspec(naked) static intptr_t raw_vcall(void *that, void *fptr, uintptr_t a0,
|
|
|
|
|
uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5)
|
|
|
|
|
{
|
|
|
|
|
// __thiscall requires that the callee cleans up the stack
|
|
|
|
|
// here we dont know how many arguments it will take, so
|
|
|
|
@ -1112,11 +1085,11 @@ __declspec(naked) static int raw_vcall(void *that, void *fptr, unsigned long a0,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
static int raw_vcall(void *that, void *fptr, unsigned long a0,
|
|
|
|
|
unsigned long a1, unsigned long a2, unsigned long a3, unsigned long a4, unsigned long a5)
|
|
|
|
|
static intptr_t raw_vcall(void *that, void *fptr, uintptr_t a0,
|
|
|
|
|
uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5)
|
|
|
|
|
{
|
|
|
|
|
int (*t_fptr)(void *me, unsigned long, unsigned long, unsigned long,
|
|
|
|
|
unsigned long, unsigned long, unsigned long);
|
|
|
|
|
intptr_t (*t_fptr)(void *me, uintptr_t, uintptr_t, uintptr_t,
|
|
|
|
|
uintptr_t, uintptr_t, uintptr_t);
|
|
|
|
|
t_fptr = (decltype(t_fptr))fptr;
|
|
|
|
|
return t_fptr(that, a0, a1, a2, a3, a4, a5);
|
|
|
|
|
}
|
|
|
|
|