More 64-bit fixes

Cherry-picked from 7eb3ba6
- Lua update already done in e2c6350, 4dd411e
- Excluded library/modules/Buildings.cpp
develop
Vitaly Pronkin 2016-07-26 23:47:53 -04:00 committed by lethosor
parent 3833ff2e09
commit fe18f176f7
15 changed files with 42 additions and 37 deletions

@ -117,8 +117,8 @@ if (NOT EXISTS ${dfhack_SOURCE_DIR}/library/xml/codegen.pl OR NOT EXISTS ${dfhac
endif() endif()
# set up versioning. # set up versioning.
set(DF_VERSION "0.43.03") set(DF_VERSION "0.43.05")
SET(DFHACK_RELEASE "r1") SET(DFHACK_RELEASE "alpha0")
SET(DFHACK_PRERELEASE FALSE) SET(DFHACK_PRERELEASE FALSE)
set(DFHACK_VERSION "${DF_VERSION}-${DFHACK_RELEASE}") set(DFHACK_VERSION "${DF_VERSION}-${DFHACK_RELEASE}")

@ -2107,7 +2107,7 @@ void Core::handleLoadAndUnloadScripts(color_ostream& out, state_change_event eve
if (!df::global::world) if (!df::global::world)
return; return;
std::string rawFolder = "data/save/" + (df::global::world->cur_savegame.save_dir) + "/raw/"; std::string rawFolder = "data/save/" + (df::global::world->save_dir) + "/raw/";
auto i = table.find(event); auto i = table.find(event);
if ( i != table.end() ) { if ( i != table.end() ) {
@ -2167,9 +2167,9 @@ void Core::onStateChange(color_ostream &out, state_change_event event)
case SC_WORLD_UNLOADED: case SC_WORLD_UNLOADED:
case SC_MAP_LOADED: case SC_MAP_LOADED:
case SC_MAP_UNLOADED: case SC_MAP_UNLOADED:
if (world && world->cur_savegame.save_dir.size()) if (world && world->save_dir.size())
{ {
std::string save_dir = "data/save/" + world->cur_savegame.save_dir; std::string save_dir = "data/save/" + world->save_dir;
std::string evtlogpath = save_dir + "/events-dfhack.log"; std::string evtlogpath = save_dir + "/events-dfhack.log";
std::ofstream evtlog; std::ofstream evtlog;
evtlog.open(evtlogpath, std::ios_base::app); // append evtlog.open(evtlogpath, std::ios_base::app); // append
@ -2187,7 +2187,7 @@ void Core::onStateChange(color_ostream &out, state_change_event event)
evtlog << timebuf; evtlog << timebuf;
evtlog << "DFHack " << Version::git_description() << " on " << ostype << "; "; evtlog << "DFHack " << Version::git_description() << " on " << ostype << "; ";
evtlog << "cwd md5: " << md5w.getHashFromString(getHackPath()).substr(0, 10) << "; "; evtlog << "cwd md5: " << md5w.getHashFromString(getHackPath()).substr(0, 10) << "; ";
evtlog << "save: " << world->cur_savegame.save_dir << "; "; evtlog << "save: " << world->save_dir << "; ";
evtlog << sc_event_name(event) << "; "; evtlog << sc_event_name(event) << "; ";
if (gametype) if (gametype)
evtlog << "game type " << ENUM_KEY_STR(game_type, *gametype) << " (" << *gametype << ")"; evtlog << "game type " << ENUM_KEY_STR(game_type, *gametype) << " (" << *gametype << ")";

@ -319,7 +319,7 @@ static int yield_helper(lua_State *S)
} }
namespace { namespace {
int dfhack_lineedit_cont(lua_State *L, int status, int) int dfhack_lineedit_cont(lua_State *L, int status, lua_KContext)
{ {
if (Lua::IsSuccess(status)) if (Lua::IsSuccess(status))
return lua_gettop(L) - 2; return lua_gettop(L) - 2;
@ -636,7 +636,7 @@ static bool do_finish_pcall(lua_State *L, bool success, int base = 1, int space
} }
namespace { namespace {
int safecall_cont(lua_State *L, int status, int) int safecall_cont(lua_State *L, int status, lua_KContext)
{ {
bool success = do_finish_pcall(L, Lua::IsSuccess(status)); bool success = do_finish_pcall(L, Lua::IsSuccess(status));
@ -1138,7 +1138,7 @@ static bool do_invoke_cleanup(lua_State *L, int nargs, int errorfun, bool succes
return success; return success;
} }
int dfhack_cleanup_cont(lua_State *L, int status, int) int dfhack_cleanup_cont(lua_State *L, int status, lua_KContext)
{ {
bool success = Lua::IsSuccess(status); bool success = Lua::IsSuccess(status);
@ -1246,6 +1246,11 @@ static int dfhack_open_plugin(lua_State *L)
return 0; return 0;
} }
static int gettop_wrapper(lua_State *L, int, lua_KContext)
{
return lua_gettop(L);
}
static int dfhack_curry_wrap(lua_State *L) static int dfhack_curry_wrap(lua_State *L)
{ {
int nargs = lua_gettop(L); int nargs = lua_gettop(L);
@ -1261,7 +1266,7 @@ static int dfhack_curry_wrap(lua_State *L)
for (int i = 1; i <= ncurry; i++) for (int i = 1; i <= ncurry; i++)
lua_copy(L, lua_upvalueindex(i+1), i); lua_copy(L, lua_upvalueindex(i+1), i);
lua_callk(L, scount-1, LUA_MULTRET, 0, lua_gettop); lua_callk(L, scount-1, LUA_MULTRET, 0, gettop_wrapper);
return lua_gettop(L); return lua_gettop(L);
} }

@ -305,7 +305,7 @@ void container_identity::lua_item_write(lua_State *state, int fname_idx, void *p
id->lua_write(state, fname_idx, pitem, val_index); id->lua_write(state, fname_idx, pitem, val_index);
} }
bool container_identity::lua_insert(lua_State *state, int fname_idx, void *ptr, int idx, int val_index) bool container_identity::lua_insert2(lua_State *state, int fname_idx, void *ptr, int idx, int val_index)
{ {
auto id = (type_identity*)lua_touserdata(state, UPVAL_ITEM_ID); auto id = (type_identity*)lua_touserdata(state, UPVAL_ITEM_ID);
@ -351,7 +351,7 @@ void ptr_container_identity::lua_item_write(lua_State *state, int fname_idx, voi
df::pointer_identity::lua_write(state, fname_idx, pitem, id, val_index); df::pointer_identity::lua_write(state, fname_idx, pitem, id, val_index);
} }
bool ptr_container_identity::lua_insert(lua_State *state, int fname_idx, void *ptr, int idx, int val_index) bool ptr_container_identity::lua_insert2(lua_State *state, int fname_idx, void *ptr, int idx, int val_index)
{ {
auto id = (type_identity*)lua_touserdata(state, UPVAL_ITEM_ID); auto id = (type_identity*)lua_touserdata(state, UPVAL_ITEM_ID);
@ -887,7 +887,7 @@ static int method_container_insert(lua_State *state)
int len = id->lua_item_count(state, ptr, container_identity::COUNT_LEN); int len = id->lua_item_count(state, ptr, container_identity::COUNT_LEN);
int idx = check_container_index(state, len, UPVAL_METHOD_NAME, 2, "call", true); int idx = check_container_index(state, len, UPVAL_METHOD_NAME, 2, "call", true);
if (!id->lua_insert(state, UPVAL_METHOD_NAME, ptr, idx, 3)) if (!id->lua_insert2(state, UPVAL_METHOD_NAME, ptr, idx, 3))
field_error(state, UPVAL_METHOD_NAME, "not supported", "call"); field_error(state, UPVAL_METHOD_NAME, "not supported", "call");
return 0; return 0;
} }

@ -386,7 +386,7 @@ static command_result GetWorldInfo(color_ostream &stream,
if (df::global::gametype) if (df::global::gametype)
gt = *df::global::gametype; gt = *df::global::gametype;
out->set_save_dir(world->cur_savegame.save_dir); out->set_save_dir(world->save_dir);
if (world->world_data->name.has_name) if (world->world_data->name.has_name)
describeName(out->mutable_world_name(), &world->world_data->name); describeName(out->mutable_world_name(), &world->world_data->name);

@ -132,7 +132,7 @@ namespace DFHack
virtual bool erase(void *ptr, int index) { return false; } virtual bool erase(void *ptr, int index) { return false; }
virtual bool insert(void *ptr, int index, void *pitem) { return false; } virtual bool insert(void *ptr, int index, void *pitem) { return false; }
virtual bool lua_insert(lua_State *state, int fname_idx, void *ptr, int idx, int val_index); virtual bool lua_insert2(lua_State *state, int fname_idx, void *ptr, int idx, int val_index);
protected: protected:
virtual int item_count(void *ptr, CountMode cnt) = 0; virtual int item_count(void *ptr, CountMode cnt) = 0;
@ -153,7 +153,7 @@ namespace DFHack
virtual void lua_item_read(lua_State *state, int fname_idx, void *ptr, int idx); virtual void lua_item_read(lua_State *state, int fname_idx, void *ptr, int idx);
virtual void lua_item_write(lua_State *state, int fname_idx, void *ptr, int idx, int val_index); virtual void lua_item_write(lua_State *state, int fname_idx, void *ptr, int idx, int val_index);
virtual bool lua_insert(lua_State *state, int fname_idx, void *ptr, int idx, int val_index); virtual bool lua_insert2(lua_State *state, int fname_idx, void *ptr, int idx, int val_index);
}; };
class DFHACK_EXPORT bit_container_identity : public container_identity { class DFHACK_EXPORT bit_container_identity : public container_identity {

@ -182,11 +182,9 @@ namespace DFHack {namespace Lua {
} }
// Internal helper // Internal helper
template<int (*cb)(lua_State*,int,int)> template<int (*cb)(lua_State*,int,lua_KContext)>
int TailPCallK_Thunk(lua_State *state) { int TailPCallK_Thunk(lua_State *state, int rv, lua_KContext ctx) {
int tmp; return cb(state, rv, ctx);
int rv = lua_getctx(state, &tmp);
return cb(state, rv, tmp);
} }
/** /**
@ -194,9 +192,9 @@ namespace DFHack {namespace Lua {
* specifically, the callback is called with the same kind of arguments * specifically, the callback is called with the same kind of arguments
* in both yield and non-yield case. * in both yield and non-yield case.
*/ */
template<int (*cb)(lua_State*,int,int)> template<int (*cb)(lua_State*,int,lua_KContext)>
int TailPCallK(lua_State *state, int narg, int nret, int errfun, int ctx) { int TailPCallK(lua_State *state, int narg, int nret, int errfun, int ctx) {
int rv = lua_pcallk(state, narg, nret, errfun, ctx, &TailPCallK_Thunk<cb>); int rv = lua_pcallk(state, narg, nret, errfun, ctx, cb);
return cb(state, rv, ctx); return cb(state, rv, ctx);
} }

@ -606,7 +606,7 @@ end
function dfhack.getSavePath() function dfhack.getSavePath()
if dfhack.isWorldLoaded() then if dfhack.isWorldLoaded() then
return dfhack.getDFPath() .. '/data/save/' .. df.global.world.cur_savegame.save_dir return dfhack.getDFPath() .. '/data/save/' .. df.global.world.save_dir
end end
end end

@ -155,6 +155,8 @@ function MemoryArea.new(astart, aend)
uint16_t = CheckedArray.new('uint16_t',astart,aend), uint16_t = CheckedArray.new('uint16_t',astart,aend),
int32_t = CheckedArray.new('int32_t',astart,aend), int32_t = CheckedArray.new('int32_t',astart,aend),
uint32_t = CheckedArray.new('uint32_t',astart,aend), uint32_t = CheckedArray.new('uint32_t',astart,aend),
int64_t = CheckedArray.new('int64_t',astart,aend),
uint64_t = CheckedArray.new('uint64_t',astart,aend),
float = CheckedArray.new('float',astart,aend) float = CheckedArray.new('float',astart,aend)
} }
setmetatable(obj, MemoryArea) setmetatable(obj, MemoryArea)
@ -321,7 +323,7 @@ end
-- Validation -- Validation
function is_valid_vector(ref,size) function is_valid_vector(ref,size)
local ints = df.reinterpret_cast('uint32_t', ref) local ints = df.reinterpret_cast('uint64_t', ref)
return ints[0] <= ints[1] and ints[1] <= ints[2] return ints[0] <= ints[1] and ints[1] <= ints[2]
and (size == nil or (ints[1] - ints[0]) % size == 0) and (size == nil or (ints[1] - ints[0]) % size == 0)
end end

@ -151,7 +151,7 @@ void World::SetCurrentWeather(uint8_t weather)
string World::ReadWorldFolder() string World::ReadWorldFolder()
{ {
return world->cur_savegame.save_dir; return world->save_dir;
} }
bool World::isFortressMode(df::game_type t) bool World::isFortressMode(df::game_type t)

@ -1 +1 @@
Subproject commit 7d312334c320022cd6275cddcdb8a64d4ed8d722 Subproject commit 369dfdd862da961c74d35174cb55fed3d96a29c0

@ -158,12 +158,12 @@ void ev_mng_jobCompleted(color_ostream& out, void* job)
} }
void ev_mng_unitDeath(color_ostream& out, void* ptr) void ev_mng_unitDeath(color_ostream& out, void* ptr)
{ {
int32_t myId=int32_t(ptr); int32_t myId=*(int32_t*)&ptr;
onUnitDeath(out,myId); onUnitDeath(out,myId);
} }
void ev_mng_itemCreate(color_ostream& out, void* ptr) void ev_mng_itemCreate(color_ostream& out, void* ptr)
{ {
int32_t myId=int32_t(ptr); int32_t myId=*(int32_t*)&ptr;
onItemCreated(out,myId); onItemCreated(out,myId);
} }
void ev_mng_construction(color_ostream& out, void* ptr) void ev_mng_construction(color_ostream& out, void* ptr)
@ -178,12 +178,12 @@ void ev_mng_syndrome(color_ostream& out, void* ptr)
} }
void ev_mng_invasion(color_ostream& out, void* ptr) void ev_mng_invasion(color_ostream& out, void* ptr)
{ {
int32_t myId=int32_t(ptr); int32_t myId=*(int32_t*)&ptr;
onInvasion(out,myId); onInvasion(out,myId);
} }
static void ev_mng_building(color_ostream& out, void* ptr) static void ev_mng_building(color_ostream& out, void* ptr)
{ {
int32_t myId=int32_t(ptr); int32_t myId=*(int32_t*)&ptr;
onBuildingCreatedDestroyed(out,myId); onBuildingCreatedDestroyed(out,myId);
} }
static void ev_mng_inventory(color_ostream& out, void* ptr) static void ev_mng_inventory(color_ostream& out, void* ptr)
@ -204,7 +204,7 @@ static void ev_mng_inventory(color_ostream& out, void* ptr)
onInventoryChange(out,unitId,itemId,item_old,item_new); onInventoryChange(out,unitId,itemId,item_old,item_new);
} }
static void ev_mng_report(color_ostream& out, void* ptr) { static void ev_mng_report(color_ostream& out, void* ptr) {
onReport(out,(int32_t)ptr); onReport(out,*(int32_t*)&ptr);
} }
static void ev_mng_unitAttack(color_ostream& out, void* ptr) { static void ev_mng_unitAttack(color_ostream& out, void* ptr) {
EventManager::UnitAttackData* data = (EventManager::UnitAttackData*)ptr; EventManager::UnitAttackData* data = (EventManager::UnitAttackData*)ptr;

@ -198,7 +198,7 @@ static command_result GetEmbarkInfo(color_ostream &stream, const MapRequest *in,
return CR_OK; return CR_OK;
} }
if (in->has_save_folder()) { //If no save folder is given, it means we don't care. if (in->has_save_folder()) { //If no save folder is given, it means we don't care.
if (!(in->save_folder() == world->cur_savegame.save_dir || in->save_folder() == "ANY")) { //isoworld has a different map loaded, don't bother trying to load tiles for it, we don't have them. if (!(in->save_folder() == world->save_dir || in->save_folder() == "ANY")) { //isoworld has a different map loaded, don't bother trying to load tiles for it, we don't have them.
out->set_available(false); out->set_available(false);
return CR_OK; return CR_OK;
} }
@ -345,7 +345,7 @@ static command_result GetRawNames(color_ostream &stream, const MapRequest *in, R
return CR_OK; return CR_OK;
} }
if (in->has_save_folder()) { //If no save folder is given, it means we don't care. if (in->has_save_folder()) { //If no save folder is given, it means we don't care.
if (!(in->save_folder() == world->cur_savegame.save_dir || in->save_folder() == "ANY")) { //isoworld has a different map loaded, don't bother trying to load tiles for it, we don't have them. if (!(in->save_folder() == world->save_dir || in->save_folder() == "ANY")) { //isoworld has a different map loaded, don't bother trying to load tiles for it, we don't have them.
out->set_available(false); out->set_available(false);
return CR_OK; return CR_OK;
} }

@ -1576,7 +1576,7 @@ static command_result GetMapInfo(color_ostream &stream, const EmptyMessage *in,
out->set_block_pos_z(pos_z); out->set_block_pos_z(pos_z);
out->set_world_name(DF2UTF(Translation::TranslateName(&df::global::world->world_data->name, false))); out->set_world_name(DF2UTF(Translation::TranslateName(&df::global::world->world_data->name, false)));
out->set_world_name_english(DF2UTF(Translation::TranslateName(&df::global::world->world_data->name, true))); out->set_world_name_english(DF2UTF(Translation::TranslateName(&df::global::world->world_data->name, true)));
out->set_save_name(df::global::world->cur_savegame.save_dir); out->set_save_name(df::global::world->save_dir);
return CR_OK; return CR_OK;
} }

@ -1172,9 +1172,9 @@ void lightingEngineViewscreen::defaultSettings()
void lightingEngineViewscreen::loadSettings() void lightingEngineViewscreen::loadSettings()
{ {
std::string rawFolder; std::string rawFolder;
if(df::global::world->cur_savegame.save_dir!="") if(df::global::world->save_dir!="")
{ {
rawFolder= "data/save/" + (df::global::world->cur_savegame.save_dir) + "/raw/"; rawFolder= "data/save/" + (df::global::world->save_dir) + "/raw/";
} }
else else
{ {