From 60f142ce96de38c4cdd0a08caa399650fc55831e Mon Sep 17 00:00:00 2001 From: nakeee Date: Sun, 8 Nov 2009 08:54:09 +0000 Subject: [PATCH] Begining of porting the luainteface to linux + some other small fixes. (could use some help with lua macros) git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4515 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/CommonFuncs.h | 1 + Source/Core/Core/Src/LuaInterface.cpp | 86 ++++++++++++------------- Source/Core/Core/Src/SConscript | 4 +- Source/Core/DolphinWX/Src/LuaWindow.cpp | 2 +- Source/Core/DolphinWX/Src/SConscript | 18 ++---- 5 files changed, 55 insertions(+), 56 deletions(-) diff --git a/Source/Core/Common/Src/CommonFuncs.h b/Source/Core/Common/Src/CommonFuncs.h index e36a8fa10a..a11169d27a 100644 --- a/Source/Core/Common/Src/CommonFuncs.h +++ b/Source/Core/Common/Src/CommonFuncs.h @@ -63,6 +63,7 @@ inline u32 _rotr(u32 x, int shift) { #define strncasecmp _strnicmp #define unlink _unlink #define snprintf _snprintf + #define vscprintf _vscprintf char* strndup (char const *s, size_t n); // 64 bit offsets for windows diff --git a/Source/Core/Core/Src/LuaInterface.cpp b/Source/Core/Core/Src/LuaInterface.cpp index 2468925b37..27ad60a9ec 100644 --- a/Source/Core/Core/Src/LuaInterface.cpp +++ b/Source/Core/Core/Src/LuaInterface.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include "zlib.h" #include "LuaInterface.h" @@ -152,14 +153,6 @@ static std::map s_cFuncInfoMap; static const char* name##_args = s_cFuncInfoMap[name] = argstring; \ static int name(lua_State* L) -#ifdef _MSC_VER - #define snprintf _snprintf - #define vscprintf _vscprintf -#else - #define __forceinline __attribute__((always_inline)) -#endif - - static const char* luaCallIDStrings [] = { "CALL_BEFOREEMULATION", @@ -187,7 +180,7 @@ static const char* luaCallIDStrings [] = "CALL_HOTKEY_15", "CALL_HOTKEY_16", }; -static const int _makeSureWeHaveTheRightNumberOfStrings [sizeof(luaCallIDStrings)/sizeof(*luaCallIDStrings) == LUACALL_COUNT ? 1 : 0]; + //static const int _makeSureWeHaveTheRightNumberOfStrings [sizeof(luaCallIDStrings)/sizeof(*luaCallIDStrings) == LUACALL_COUNT ? 1 : 0]; static const char* luaMemHookTypeStrings [] = { @@ -199,7 +192,7 @@ static const char* luaMemHookTypeStrings [] = "MEMHOOK_READ_SUB", "MEMHOOK_EXEC_SUB", }; -static const int _makeSureWeHaveTheRightNumberOfStrings2 [sizeof(luaMemHookTypeStrings)/sizeof(*luaMemHookTypeStrings) == LUAMEMHOOK_COUNT ? 1 : 0]; + //static const int _makeSureWeHaveTheRightNumberOfStrings2 [sizeof(luaMemHookTypeStrings)/sizeof(*luaMemHookTypeStrings) == LUAMEMHOOK_COUNT ? 1 : 0]; void StopScriptIfFinished(int uid, bool justReturned = false); void SetSaveKey(LuaContextInfo& info, const char* key); @@ -216,7 +209,7 @@ static int memory_registerHook(lua_State* L, LuaMemHookType hookType, int defaul { // get first argument: address unsigned int addr = (unsigned int)luaL_checkinteger(L,1); - if((addr & ~0xFFFFFF) == ~0xFFFFFF) + if((addr & ~0xFFFFFF) == (unsigned int)~0xFFFFFF) addr &= 0xFFFFFF; // get optional second argument: size @@ -300,6 +293,11 @@ LuaMemHookType MatchHookTypeToCPU(lua_State* L, LuaMemHookType hookType) case LUAMEMHOOK_WRITE: return LUAMEMHOOK_WRITE_SUB; case LUAMEMHOOK_READ: return LUAMEMHOOK_READ_SUB; case LUAMEMHOOK_EXEC: return LUAMEMHOOK_EXEC_SUB; + case LUAMEMHOOK_WRITE_SUB: + case LUAMEMHOOK_READ_SUB: + case LUAMEMHOOK_EXEC_SUB: + case LUAMEMHOOK_COUNT: + break; } } return hookType; @@ -798,8 +796,8 @@ static void toCStringConverter(lua_State* L, int i, char*& ptr, int& remaining) case LUA_TNONE: break; case LUA_TNIL: APPENDPRINT "nil" END break; case LUA_TBOOLEAN: APPENDPRINT lua_toboolean(L,i) ? "true" : "false" END break; - case LUA_TSTRING: APPENDPRINT "%s",lua_tostring(L,i) END break; - case LUA_TNUMBER: APPENDPRINT "%.12Lg",lua_tonumber(L,i) END break; + case LUA_TSTRING: APPENDPRINT "%s", lua_tostring(L,i) END break; + case LUA_TNUMBER: APPENDPRINT "%.12Lg", (long double)lua_tonumber(L,i) END break; case LUA_TFUNCTION: if((L->base + i-1)->value.gc->cl.c.isC) { @@ -874,20 +872,20 @@ defcase:default: APPENDPRINT "%s:%p",luaL_typename(L,i),lua_topointer(L,i) END b { bool keyIsString = (lua_type(L, keyIndex) == LUA_TSTRING); bool invalidLuaIdentifier = (!keyIsString || !isalphaorunderscore(*lua_tostring(L, keyIndex))); - if(invalidLuaIdentifier) - if(keyIsString) + if(invalidLuaIdentifier) { + if(keyIsString) APPENDPRINT "['" END else APPENDPRINT "[" END - + } toCStringConverter(L, keyIndex, ptr, remaining); // key - if(invalidLuaIdentifier) + if(invalidLuaIdentifier) { if(keyIsString) APPENDPRINT "']=" END else APPENDPRINT "]=" END - else + } else APPENDPRINT "=" END } @@ -4219,7 +4217,7 @@ static void PushNils(std::vector& output, int& nilcount) else { output.push_back(LUAEXT_TNILS); - PushBinaryItem(count, output); + PushBinaryItem(count, output); } } @@ -4270,7 +4268,7 @@ static void LuaStackToBinaryConverter(lua_State* L, int i, std::vector(inum, output); + PushBinaryItem(inum, output); break; case LUAEXT_TUSHORT: - PushBinaryItem(inum, output); + PushBinaryItem(inum, output); break; case LUAEXT_TSHORT: - PushBinaryItem(inum, output); + PushBinaryItem(inum, output); break; case LUAEXT_TBYTE: output.push_back(inum); @@ -4305,10 +4303,12 @@ static void LuaStackToBinaryConverter(lua_State* L, int i, std::vector(data, remaining)); + lua_pushboolean(L, AdvanceByteStream(data, remaining)); break; case LUA_TSTRING: lua_pushstring(L, (const char*)data); @@ -4442,16 +4442,16 @@ void BinaryToLuaStackConverter(lua_State* L, const unsigned char*& data, unsigne lua_pushnumber(L, AdvanceByteStream(data, remaining)); break; case LUAEXT_TLONG: - lua_pushinteger(L, AdvanceByteStream(data, remaining)); + lua_pushinteger(L, AdvanceByteStream(data, remaining)); break; case LUAEXT_TUSHORT: - lua_pushinteger(L, AdvanceByteStream(data, remaining)); + lua_pushinteger(L, AdvanceByteStream(data, remaining)); break; case LUAEXT_TSHORT: - lua_pushinteger(L, AdvanceByteStream(data, remaining)); + lua_pushinteger(L, AdvanceByteStream(data, remaining)); break; case LUAEXT_TBYTE: - lua_pushinteger(L, AdvanceByteStream(data, remaining)); + lua_pushinteger(L, AdvanceByteStream(data, remaining)); break; case LUAEXT_TTABLE: case LUAEXT_TTABLE | LUAEXT_BITS_1A: @@ -4472,21 +4472,21 @@ void BinaryToLuaStackConverter(lua_State* L, const unsigned char*& data, unsigne { unsigned int arraySize = 0; if(BITMATCH(type,LUAEXT_BITS_4A) || BITMATCH(type,LUAEXT_BITS_2A) || BITMATCH(type,LUAEXT_BITS_1A)) - arraySize |= AdvanceByteStream(data, remaining); + arraySize |= AdvanceByteStream(data, remaining); if(BITMATCH(type,LUAEXT_BITS_4A) || BITMATCH(type,LUAEXT_BITS_2A)) - arraySize |= ((UINT16)AdvanceByteStream(data, remaining)) << 8; + arraySize |= ((u16)AdvanceByteStream(data, remaining)) << 8; if(BITMATCH(type,LUAEXT_BITS_4A)) - arraySize |= ((UINT32)AdvanceByteStream(data, remaining)) << 16, - arraySize |= ((UINT32)AdvanceByteStream(data, remaining)) << 24; + arraySize |= ((u32)AdvanceByteStream(data, remaining)) << 16, + arraySize |= ((u32)AdvanceByteStream(data, remaining)) << 24; unsigned int hashSize = 0; if(BITMATCH(type,LUAEXT_BITS_4H) || BITMATCH(type,LUAEXT_BITS_2H) || BITMATCH(type,LUAEXT_BITS_1H)) - hashSize |= AdvanceByteStream(data, remaining); + hashSize |= AdvanceByteStream(data, remaining); if(BITMATCH(type,LUAEXT_BITS_4H) || BITMATCH(type,LUAEXT_BITS_2H)) - hashSize |= ((UINT16)AdvanceByteStream(data, remaining)) << 8; + hashSize |= ((u16)AdvanceByteStream(data, remaining)) << 8; if(BITMATCH(type,LUAEXT_BITS_4H)) - hashSize |= ((UINT32)AdvanceByteStream(data, remaining)) << 16, - hashSize |= ((UINT32)AdvanceByteStream(data, remaining)) << 24; + hashSize |= ((u32)AdvanceByteStream(data, remaining)) << 16, + hashSize |= ((u32)AdvanceByteStream(data, remaining)) << 24; lua_createtable(L, arraySize, hashSize); @@ -4496,7 +4496,7 @@ void BinaryToLuaStackConverter(lua_State* L, const unsigned char*& data, unsigne if(*data == LUAEXT_TNILS) { AdvanceByteStream(data, remaining, 1); - n += AdvanceByteStream(data, remaining); + n += AdvanceByteStream(data, remaining); } else { diff --git a/Source/Core/Core/Src/SConscript b/Source/Core/Core/Src/SConscript index ab53ca6ea7..3ddbdcb604 100644 --- a/Source/Core/Core/Src/SConscript +++ b/Source/Core/Core/Src/SConscript @@ -16,6 +16,7 @@ files = ["ActionReplay.cpp", "MemTools.cpp", "PatchEngine.cpp", "PluginManager.cpp", + "LuaInterface.cpp", "State.cpp", "Tracer.cpp", "VolumeHandler.cpp", @@ -84,7 +85,7 @@ files = ["ActionReplay.cpp", "PowerPC/Interpreter/Interpreter_LoadStore.cpp", "PowerPC/Interpreter/Interpreter_LoadStorePaired.cpp", "PowerPC/Interpreter/Interpreter_SystemRegisters.cpp", - "PowerPC/Interpreter/Interpreter_Tables.cpp", + "PowerPC/Interpreter/Interpreter_Tables.cpp", "PowerPC/JitCommon/JitCache.cpp", "PowerPC/JitCommon/JitBackpatch.cpp", "PowerPC/JitCommon/Jit_Util.cpp", @@ -136,6 +137,7 @@ else: libs = [ 'bdisasm', 'inputcommon', + 'lua' ] env_core = env.Clone(); diff --git a/Source/Core/DolphinWX/Src/LuaWindow.cpp b/Source/Core/DolphinWX/Src/LuaWindow.cpp index 8a2ee24b79..5699c91e2b 100644 --- a/Source/Core/DolphinWX/Src/LuaWindow.cpp +++ b/Source/Core/DolphinWX/Src/LuaWindow.cpp @@ -145,7 +145,7 @@ void wxLuaWindow::OnEvent_ScriptLoad_Press(wxCommandEvent& WXUNUSED(event)) m_TextCtrl_Log->Clear(); m_TextCtrl_Log->AppendText(wxString::FromAscii( StringFromFormat("Script %s loaded successfully.\n", - path.mb_str()).c_str())); + (const char *)path.mb_str()).c_str())); m_Button_Run->Enable(); } diff --git a/Source/Core/DolphinWX/Src/SConscript b/Source/Core/DolphinWX/Src/SConscript index 40694264e8..60bdf0a8ae 100644 --- a/Source/Core/DolphinWX/Src/SConscript +++ b/Source/Core/DolphinWX/Src/SConscript @@ -10,16 +10,10 @@ files = [ 'cmdline.c', ] -if wxenv['HAVE_WX']: - libs = [ - 'core', 'minilzo', 'discio', 'bdisasm', 'videocommon', 'inputcommon', - 'common', 'z', 'debugger_ui_util' - ] -else: - libs = [ - 'core', 'minilzo', 'discio', 'bdisasm', 'videocommon', 'inputcommon', - 'common', 'z' - ] +libs = [ + 'core', 'minilzo', 'discio', 'bdisasm', 'videocommon', + 'inputcommon', 'common', 'lua', 'z' + ] if wxenv['HAVE_WX']: files += [ @@ -30,6 +24,7 @@ if wxenv['HAVE_WX']: 'FrameAui.cpp', 'FrameTools.cpp', 'FrameWiimote.cpp', + 'LuaWindow.cpp', 'LogWindow.cpp', 'GameListCtrl.cpp', 'Globals.cpp', @@ -49,7 +44,8 @@ if wxenv['HAVE_WX']: 'wxNEEDS_CHARPP', ], - libs = [ 'debwx' ] + libs + libs = [ 'debwx', 'debugger_ui_util'] + libs + if wxenv['HAVE_SFML']: files += [ 'NetEvent.cpp',