lua scripting

This commit is contained in:
p989 2009-06-26 06:10:28 +00:00
parent 918afdcb2b
commit 20b89b2b49
6 changed files with 2090 additions and 1 deletions

1945
desmume/src/lua-engine.cpp Normal file

File diff suppressed because it is too large Load Diff

32
desmume/src/lua-engine.h Normal file
View File

@ -0,0 +1,32 @@
#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

View File

@ -375,6 +375,10 @@
RelativePath="..\GPU_OSD.cpp"
>
</File>
<File
RelativePath="..\lua-engine.cpp"
>
</File>
<File
RelativePath="..\matrix.cpp"
>
@ -1029,6 +1033,10 @@
RelativePath="..\GPU_osd.h"
>
</File>
<File
RelativePath="..\lua-engine.h"
>
</File>
<File
RelativePath="..\matrix.h"
>

View File

@ -83,6 +83,7 @@
#include "aviout.h"
#include "soundView.h"
#include "commandline.h"
#include "../lua-engine.h"
#include "directx/ddraw.h"
@ -184,6 +185,8 @@ char ImportSavName[MAX_PATH] = "";
char szClassName[ ] = "DeSmuME";
int romnum = 0;
void LuaRunFrom(void);
DWORD threadID;
WINCLASS *MainWindow=NULL;
@ -1114,6 +1117,7 @@ DWORD WINAPI run()
while(execute)
{
input_process();
LUA_LuaFrameBoundary();
FCEUMOV_AddInputState();
if (ShowInputDisplay) osd->addFixed(Hud.InputDisplay.x, Hud.InputDisplay.y, "%s",InputDisplayString.c_str());
@ -3053,6 +3057,16 @@ 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:
@ -3453,7 +3467,6 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
if(tpaused) NDS_UnPause();
}
return 0;
case IDC_FRAMESKIPAUTO:
case IDC_FRAMESKIP0:
case IDC_FRAMESKIP1:
@ -4358,4 +4371,92 @@ 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);
}

View File

@ -101,6 +101,9 @@
#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_DES_BOX 402
#define IDC_R0 403
#define IDC_R1 404

Binary file not shown.