lua: multiple vms with callbacks, string printing and console output, editing a script has immediate effects, clean up some libs and win32 menus
This commit is contained in:
parent
1119a788ef
commit
da7cb2fede
File diff suppressed because it is too large
Load Diff
|
@ -1,32 +1,95 @@
|
|||
#ifndef _S9XLUA_H
|
||||
#define _S9XLUA_H
|
||||
|
||||
|
||||
// Just forward function declarations
|
||||
|
||||
//void LUA_LuaWrite(uint32 addr);
|
||||
void LUA_LuaFrameBoundary();
|
||||
int LUA_LoadLuaCode(const char *filename);
|
||||
void LUA_ReloadLuaCode();
|
||||
void LUA_LuaStop();
|
||||
int LUA_LuaRunning();
|
||||
|
||||
int LUA_LuaUsingJoypad(int);
|
||||
uint8 LUA_LuaReadJoypad(int);
|
||||
int LUA_LuaSpeed();
|
||||
int LUA_LuaFrameskip();
|
||||
int LUA_LuaRerecordCountSkip();
|
||||
|
||||
void LUA_LuaGui(uint8 *XBuf);
|
||||
void LUA_LuaUpdatePalette();
|
||||
|
||||
// And some interesting REVERSE declarations!
|
||||
char *LUA_GetFreezeFilename(int slot);
|
||||
|
||||
// Call this before writing into a buffer passed to LUA_CheatAddRAM().
|
||||
// (That way, Lua-based memwatch will work as expected for somebody
|
||||
// used to LUA's memwatch.)
|
||||
void LUA_LuaWriteInform();
|
||||
|
||||
|
||||
#endif
|
||||
#ifndef LUA_SCRIPT_H
|
||||
#define LUA_SCRIPT_H
|
||||
|
||||
|
||||
void OpenLuaContext(int uid, void(*print)(int uid, const char* str) = 0, void(*onstart)(int uid) = 0, void(*onstop)(int uid, bool statusOK) = 0);
|
||||
void RunLuaScriptFile(int uid, const char* filename);
|
||||
void StopLuaScript(int uid);
|
||||
void RequestAbortLuaScript(int uid, const char* message = 0);
|
||||
void CloseLuaContext(int uid);
|
||||
|
||||
enum LuaCallID
|
||||
{
|
||||
LUACALL_BEFOREEMULATION,
|
||||
LUACALL_AFTEREMULATION,
|
||||
LUACALL_AFTEREMULATIONGUI,
|
||||
LUACALL_BEFOREEXIT,
|
||||
LUACALL_BEFORESAVE,
|
||||
LUACALL_AFTERLOAD,
|
||||
LUACALL_ONSTART,
|
||||
|
||||
LUACALL_SCRIPT_HOTKEY_1,
|
||||
LUACALL_SCRIPT_HOTKEY_2,
|
||||
LUACALL_SCRIPT_HOTKEY_3,
|
||||
LUACALL_SCRIPT_HOTKEY_4,
|
||||
LUACALL_SCRIPT_HOTKEY_5,
|
||||
LUACALL_SCRIPT_HOTKEY_6,
|
||||
LUACALL_SCRIPT_HOTKEY_7,
|
||||
LUACALL_SCRIPT_HOTKEY_8,
|
||||
LUACALL_SCRIPT_HOTKEY_9,
|
||||
LUACALL_SCRIPT_HOTKEY_10,
|
||||
LUACALL_SCRIPT_HOTKEY_11,
|
||||
LUACALL_SCRIPT_HOTKEY_12,
|
||||
LUACALL_SCRIPT_HOTKEY_13,
|
||||
LUACALL_SCRIPT_HOTKEY_14,
|
||||
LUACALL_SCRIPT_HOTKEY_15,
|
||||
LUACALL_SCRIPT_HOTKEY_16,
|
||||
|
||||
LUACALL_COUNT
|
||||
};
|
||||
void CallRegisteredLuaFunctions(LuaCallID calltype);
|
||||
|
||||
enum LuaMemHookType
|
||||
{
|
||||
LUAMEMHOOK_WRITE,
|
||||
LUAMEMHOOK_READ,
|
||||
LUAMEMHOOK_EXEC,
|
||||
LUAMEMHOOK_WRITE_SUB,
|
||||
LUAMEMHOOK_READ_SUB,
|
||||
LUAMEMHOOK_EXEC_SUB,
|
||||
|
||||
LUAMEMHOOK_COUNT
|
||||
};
|
||||
void CallRegisteredLuaMemHook(unsigned int address, int size, unsigned int value, LuaMemHookType hookType);
|
||||
|
||||
struct LuaSaveData
|
||||
{
|
||||
LuaSaveData() { recordList = 0; }
|
||||
~LuaSaveData() { ClearRecords(); }
|
||||
|
||||
struct Record
|
||||
{
|
||||
unsigned int key; // crc32
|
||||
unsigned int size; // size of data
|
||||
unsigned char* data;
|
||||
Record* next;
|
||||
};
|
||||
|
||||
Record* recordList;
|
||||
|
||||
void SaveRecord(int uid, unsigned int key); // saves Lua stack into a record and pops it
|
||||
void LoadRecord(int uid, unsigned int key, unsigned int itemsToLoad) const; // pushes a record's data onto the Lua stack
|
||||
void SaveRecordPartial(int uid, unsigned int key, int idx); // saves part of the Lua stack (at the given index) into a record and does NOT pop anything
|
||||
|
||||
void ExportRecords(void* file) const; // writes all records to an already-open file
|
||||
void ImportRecords(void* file); // reads records from an already-open file
|
||||
void ClearRecords(); // deletes all record data
|
||||
|
||||
private:
|
||||
// disallowed, it's dangerous to call this
|
||||
// (because the memory the destructor deletes isn't refcounted and shouldn't need to be copied)
|
||||
// so pass LuaSaveDatas by reference and this should never get called
|
||||
LuaSaveData(const LuaSaveData& copy) {}
|
||||
};
|
||||
void CallRegisteredLuaSaveFunctions(int savestateNumber, LuaSaveData& saveData);
|
||||
void CallRegisteredLuaLoadFunctions(int savestateNumber, const LuaSaveData& saveData);
|
||||
|
||||
void StopAllLuaScripts();
|
||||
void RestartAllLuaScripts();
|
||||
void EnableStopAllLuaScripts(bool enable);
|
||||
void DontWorryLua();
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -64,11 +64,6 @@ struct LuaPerWindowInfo {
|
|||
std::map<HWND, LuaPerWindowInfo> LuaWindowInfo;
|
||||
static char Lua_Dir[1024]="";
|
||||
|
||||
void RequestAbortLuaScript(int uid, const char* message) {
|
||||
LUA_LuaStop();
|
||||
}
|
||||
|
||||
|
||||
int WINAPI FileSysWatcher (LPVOID arg)
|
||||
{
|
||||
HWND hDlg = (HWND)arg;
|
||||
|
@ -354,13 +349,6 @@ void UpdateFileEntered(HWND hDlg)
|
|||
|
||||
//extern "C" int Clear_Sound_Buffer(void);
|
||||
|
||||
void RunLuaScriptFile(int uid, const char* filenameCStr) {
|
||||
LUA_LoadLuaCode(filenameCStr);
|
||||
}
|
||||
void StopLuaScript(int uid) {
|
||||
LUA_LuaStop();
|
||||
}
|
||||
|
||||
static int Change_File_L(char *Dest, char *Dir, char *Titre, char *Filter, char *Ext, HWND hwnd)
|
||||
{
|
||||
OPENFILENAME ofn;
|
||||
|
@ -459,7 +447,7 @@ LRESULT CALLBACK LuaScriptProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
|
|||
LuaWindowInfo[hDlg] = info;
|
||||
RegisterWatcherThread(hDlg);
|
||||
|
||||
// OpenLuaContext((int)hDlg, PrintToWindowConsole, OnStart, OnStop);
|
||||
OpenLuaContext((int)hDlg, PrintToWindowConsole, OnStart, OnStop);
|
||||
|
||||
DragAcceptFiles(hDlg, TRUE);
|
||||
|
||||
|
@ -668,7 +656,7 @@ LRESULT CALLBACK LuaScriptProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
|
|||
KillWatcherThread(hDlg);
|
||||
LuaScriptHWnds.erase(remove(LuaScriptHWnds.begin(), LuaScriptHWnds.end(), hDlg), LuaScriptHWnds.end());
|
||||
LuaWindowInfo.erase(hDlg);
|
||||
// CloseLuaContext((int)hDlg);
|
||||
CloseLuaContext((int)hDlg);
|
||||
// Build_Main_Menu();
|
||||
EndDialog(hDlg, true);
|
||||
}
|
||||
|
@ -701,7 +689,7 @@ LRESULT CALLBACK LuaScriptProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
|
|||
KillWatcherThread(hDlg);
|
||||
LuaScriptHWnds.erase(remove(LuaScriptHWnds.begin(), LuaScriptHWnds.end(), hDlg), LuaScriptHWnds.end());
|
||||
LuaWindowInfo.erase(hDlg);
|
||||
// CloseLuaContext((int)hDlg);
|
||||
CloseLuaContext((int)hDlg);
|
||||
// Build_Main_Menu();
|
||||
EndDialog(hDlg, true);
|
||||
} return true;
|
||||
|
@ -714,6 +702,7 @@ LRESULT CALLBACK LuaScriptProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
|
|||
SendDlgItemMessage(hDlg,IDC_EDIT_LUAPATH,WM_SETTEXT,0,(LPARAM)Str_Tmp );
|
||||
UpdateFileEntered(hDlg);
|
||||
} return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -180,8 +180,6 @@ char ImportSavName[MAX_PATH] = "";
|
|||
char szClassName[ ] = "DeSmuME";
|
||||
int romnum = 0;
|
||||
|
||||
void LuaRunFrom(void);
|
||||
|
||||
DWORD threadID;
|
||||
|
||||
WINCLASS *MainWindow=NULL;
|
||||
|
@ -1021,7 +1019,7 @@ DWORD WINAPI run()
|
|||
while(execute)
|
||||
{
|
||||
input_process();
|
||||
LUA_LuaFrameBoundary();
|
||||
CallRegisteredLuaFunctions(LUACALL_BEFOREEMULATION);
|
||||
FCEUMOV_AddInputState();
|
||||
|
||||
if (ShowInputDisplay) osd->addFixed(Hud.InputDisplay.x, Hud.InputDisplay.y, "%s",InputDisplayString.c_str());
|
||||
|
@ -1033,6 +1031,8 @@ DWORD WINAPI run()
|
|||
}
|
||||
DRV_AviVideoUpdate((u16*)GPU_screen);
|
||||
|
||||
CallRegisteredLuaFunctions(LUACALL_AFTEREMULATION);
|
||||
|
||||
static int fps3d = 0;
|
||||
|
||||
if (FpsDisplay) osd->addFixed(Hud.FpsDisplay.x, Hud.FpsDisplay.y, "Fps:%02d/%02d", fps, fps3d);
|
||||
|
@ -3077,16 +3077,6 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
|
|||
NDS_UnPause();
|
||||
}
|
||||
return 0;
|
||||
case ID_FILE_RUNLUASCRIPT:
|
||||
LuaRunFrom();
|
||||
break;
|
||||
|
||||
case ID_FILE_STOPLUASCRIPT:
|
||||
LUA_LuaStop();
|
||||
break;
|
||||
case ID_FILE_RELOADLUASCRIPT:
|
||||
LUA_ReloadLuaCode();
|
||||
break;
|
||||
case IDM_STATE_SAVE_F1:
|
||||
case IDM_STATE_SAVE_F2:
|
||||
case IDM_STATE_SAVE_F3:
|
||||
|
@ -4416,95 +4406,6 @@ void UpdateHotkeyAssignments()
|
|||
*/
|
||||
}
|
||||
|
||||
INT_PTR CALLBACK DlgLuaScriptDialog(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
|
||||
|
||||
static int *success;
|
||||
|
||||
switch (msg) {
|
||||
case WM_INITDIALOG:
|
||||
{
|
||||
|
||||
// Nothing very useful to do
|
||||
success = (int*)lParam;
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
case WM_COMMAND:
|
||||
switch (LOWORD(wParam)) {
|
||||
case IDOK:
|
||||
{
|
||||
char filename[MAX_PATH];
|
||||
GetDlgItemText(hDlg, 1096, filename, MAX_PATH);
|
||||
if (LUA_LoadLuaCode(filename)) {
|
||||
*success = 1;
|
||||
// For user's convenience, don't close dialog unless we're done.
|
||||
// Users who make syntax errors and fix/reload will thank us.
|
||||
EndDialog(hDlg, 1);
|
||||
} else {
|
||||
//MessageBox(hDlg, "Couldn't load script.", "Oops", MB_OK); // XXX better if errors are displayed by the Lua code.
|
||||
*success = 0;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
case IDCANCEL:
|
||||
{
|
||||
EndDialog(hDlg, 0);
|
||||
return TRUE;
|
||||
}
|
||||
case 1359:
|
||||
{
|
||||
OPENFILENAME ofn;
|
||||
char szFileName[MAX_PATH];
|
||||
szFileName[0] = '\0';
|
||||
ZeroMemory( (LPVOID)&ofn, sizeof(OPENFILENAME) );
|
||||
ofn.lStructSize = sizeof(OPENFILENAME);
|
||||
ofn.hwndOwner = hDlg;
|
||||
ofn.lpstrFilter = "Lua scripts\0*.lua\0All files\0*.*\0\0";
|
||||
ofn.lpstrFile = szFileName;
|
||||
ofn.lpstrDefExt = "lua";
|
||||
ofn.nMaxFile = MAX_PATH;
|
||||
ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST; // hide previously-ignored read-only checkbox (the real read-only box is in the open-movie dialog itself)
|
||||
if(GetOpenFileName( &ofn ))
|
||||
{
|
||||
SetWindowText(GetDlgItem(hDlg, 1096), szFileName);
|
||||
}
|
||||
//SetCurrentDirectory(movieDirectory);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//char message[1024];
|
||||
// sprintf(message, "Unkonwn command %d,%d",msg,wParam);
|
||||
//MessageBox(hDlg, message, TEXT("Range Error"), MB_OK);
|
||||
|
||||
// printf("Unknown entry %d,%d,%d\n",msg,wParam,lParam);
|
||||
// All else, fall off
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
|
||||
void LuaRunFrom(void)
|
||||
{
|
||||
int success = 0;
|
||||
|
||||
//StopSound();
|
||||
|
||||
DialogBoxParam(hAppInst, "IDD_LUA_ADD", MainWindow->getHWnd(), DlgLuaScriptDialog,(LPARAM) &success);
|
||||
}
|
||||
|
||||
void UpdateLuaMenus()
|
||||
{
|
||||
MENUITEMINFO mii;
|
||||
ZeroMemory( &mii, sizeof( mii));
|
||||
mii.cbSize = sizeof( mii);
|
||||
mii.fMask = MIIM_STATE;
|
||||
mii.fState = MFS_UNCHECKED;
|
||||
SetMenuItemInfo (mainMenu, ID_FILE_RUNLUASCRIPT, FALSE, &mii);
|
||||
if (!LUA_LuaRunning()) mii.fState |= MFS_DISABLED;
|
||||
SetMenuItemInfo (mainMenu, ID_FILE_STOPLUASCRIPT, FALSE, &mii);
|
||||
}
|
||||
|
||||
static char Lua_Dir [1024];
|
||||
char Desmume_Path [1024];
|
||||
|
@ -4552,7 +4453,7 @@ const char* MakeScriptPathAbsolute(const char* filename, const char* extraDirToC
|
|||
|
||||
extern void RequestAbortLuaScript(int uid, const char* message);
|
||||
|
||||
const char* OpenLuaScriptConsole(const char* filename, const char* extraDirToCheck)
|
||||
const char* OpenLuaScript(const char* filename, const char* extraDirToCheck, bool makeSubservient)
|
||||
{
|
||||
if(LuaScriptHWnds.size() < 16)
|
||||
{
|
||||
|
@ -4582,4 +4483,4 @@ const char* OpenLuaScriptConsole(const char* filename, const char* extraDirToChe
|
|||
else return "Too many script windows are already open.";
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,9 +101,6 @@
|
|||
#define IDC_16_BIT 303
|
||||
#define IDC_32_BIT 304
|
||||
#define IDC_BACKGROUNDPAUSE 305
|
||||
#define ID_FILE_RUNLUASCRIPT 306
|
||||
#define ID_FILE_STOPLUASCRIPT 307
|
||||
#define ID_FILE_RELOADLUASCRIPT 308
|
||||
#define IDC_LUACONSOLE 309
|
||||
#define IDC_EDIT_LUAPATH 310
|
||||
#define IDC_BUTTON_LUARUN 311
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue