W32 LUA: Add argument capabilities to scripts -- appears as variable "arg", which may sometimes be null. (Modified file also adds a second screenshot capability to lua.)
This commit is contained in:
parent
98f713f6ab
commit
088c065c9d
|
@ -34,6 +34,7 @@ struct ControlLayoutState
|
|||
static ControlLayoutInfo controlLayoutInfos [] = {
|
||||
{IDC_LUACONSOLE, ControlLayoutInfo::RESIZE_END, ControlLayoutInfo::RESIZE_END},
|
||||
{IDC_EDIT_LUAPATH, ControlLayoutInfo::RESIZE_END, ControlLayoutInfo::NONE},
|
||||
{IDC_EDIT_LUAARGS, ControlLayoutInfo::RESIZE_END, ControlLayoutInfo::NONE},
|
||||
{IDC_BUTTON_LUARUN, ControlLayoutInfo::MOVE_START, ControlLayoutInfo::NONE},
|
||||
{IDC_BUTTON_LUASTOP, ControlLayoutInfo::MOVE_START, ControlLayoutInfo::NONE},
|
||||
};
|
||||
|
@ -73,7 +74,7 @@ void WinLuaOnStart(int hDlgAsInt)
|
|||
//info.started = true;
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_LUABROWSE), false); // disable browse while running because it misbehaves if clicked in a frameadvance loop
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_LUASTOP), true);
|
||||
SetWindowText(GetDlgItem(hDlg, IDC_BUTTON_LUARUN), "Restart");
|
||||
SetWindowText(GetDlgItem(hDlg, IDC_BUTTON_LUARUN), "&Restart");
|
||||
SetWindowText(GetDlgItem(hDlg, IDC_LUACONSOLE), ""); // clear the console
|
||||
// Show_Genesis_Screen(HWnd); // otherwise we might never show the first thing the script draws
|
||||
}
|
||||
|
@ -90,7 +91,7 @@ void WinLuaOnStop(int hDlgAsInt)
|
|||
//info.started = false;
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_LUABROWSE), true);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_LUASTOP), false);
|
||||
SetWindowText(GetDlgItem(hDlg, IDC_BUTTON_LUARUN), "Run");
|
||||
SetWindowText(GetDlgItem(hDlg, IDC_BUTTON_LUARUN), "&Run");
|
||||
// if(statusOK)
|
||||
// Show_Genesis_Screen(MainWindow->getHWnd()); // otherwise we might never show the last thing the script draws
|
||||
//if(info.closeOnStop)
|
||||
|
@ -118,17 +119,18 @@ INT_PTR CALLBACK DlgLuaScriptDialog(HWND hDlg, UINT msg, WPARAM wParam, LPARAM l
|
|||
dx2 = (r2.right - r2.left) / 2;
|
||||
dy2 = (r2.bottom - r2.top) / 2;
|
||||
|
||||
int windowIndex = 0;//std::find(LuaScriptHWnds.begin(), LuaScriptHWnds.end(), hDlg) - LuaScriptHWnds.begin();
|
||||
int staggerOffset = windowIndex * 24;
|
||||
r.left += staggerOffset;
|
||||
r.right += staggerOffset;
|
||||
r.top += staggerOffset;
|
||||
r.bottom += staggerOffset;
|
||||
//int windowIndex = 0;//std::find(LuaScriptHWnds.begin(), LuaScriptHWnds.end(), hDlg) - LuaScriptHWnds.begin();
|
||||
//int staggerOffset = windowIndex * 24;
|
||||
//r.left += staggerOffset;
|
||||
//r.right += staggerOffset;
|
||||
//r.top += staggerOffset;
|
||||
//r.bottom += staggerOffset;
|
||||
|
||||
// push it away from the main window if we can
|
||||
const int width = (r.right-r.left);
|
||||
const int width2 = (r2.right-r2.left);
|
||||
if(r.left+width2 + width < GetSystemMetrics(SM_CXSCREEN))
|
||||
const int rspace = GetSystemMetrics(SM_CXSCREEN)- (r.left+width2+width);
|
||||
if(rspace > r.left && r.left+width2 + width < GetSystemMetrics(SM_CXSCREEN))
|
||||
{
|
||||
r.right += width;
|
||||
r.left += width;
|
||||
|
@ -138,6 +140,11 @@ INT_PTR CALLBACK DlgLuaScriptDialog(HWND hDlg, UINT msg, WPARAM wParam, LPARAM l
|
|||
r.right -= width2;
|
||||
r.left -= width2;
|
||||
}
|
||||
else if(r.left+width2 + width < GetSystemMetrics(SM_CXSCREEN))
|
||||
{
|
||||
r.right += width;
|
||||
r.left += width;
|
||||
}
|
||||
|
||||
SetWindowPos(hDlg, NULL, r.left, r.top, NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
|
||||
|
||||
|
@ -236,8 +243,10 @@ INT_PTR CALLBACK DlgLuaScriptDialog(HWND hDlg, UINT msg, WPARAM wParam, LPARAM l
|
|||
case IDC_BUTTON_LUARUN:
|
||||
{
|
||||
char filename[MAX_PATH];
|
||||
char args[MAX_PATH];
|
||||
GetDlgItemText(hDlg, IDC_EDIT_LUAPATH, filename, MAX_PATH);
|
||||
FCEU_LoadLuaCode(filename);
|
||||
GetDlgItemText(hDlg, IDC_EDIT_LUAARGS, args, MAX_PATH);
|
||||
FCEU_LoadLuaCode(filename, args);
|
||||
} break;
|
||||
|
||||
case IDC_BUTTON_LUASTOP:
|
||||
|
|
|
@ -104,7 +104,6 @@
|
|||
// External functions
|
||||
extern std::string cfgFile; //Contains the filename of the config file used.
|
||||
extern bool turbo; //Is game in turbo mode?
|
||||
extern int FCEU_LoadLuaCode(const char *filename); //From lua-engine.cpp. Used here to auto-load a lua script from commandline
|
||||
void ResetVideo(void);
|
||||
void ShowCursorAbs(int w);
|
||||
void HideFWindow(int h);
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
|
@ -1464,14 +1465,16 @@ CAPTION "Lua Script"
|
|||
MENU LUAWINDOW_MENU
|
||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||
BEGIN
|
||||
PUSHBUTTON "Browse...",IDC_BUTTON_LUABROWSE,7,31,48,16
|
||||
PUSHBUTTON "Run",IDC_BUTTON_LUARUN,213,31,50,16
|
||||
PUSHBUTTON "Stop",IDC_BUTTON_LUASTOP,160,31,50,16
|
||||
PUSHBUTTON "&Browse...",IDC_BUTTON_LUABROWSE,7,31,48,16
|
||||
PUSHBUTTON "&Run",IDC_BUTTON_LUARUN,213,31,50,16
|
||||
PUSHBUTTON "&Stop",IDC_BUTTON_LUASTOP,160,31,50,16
|
||||
EDITTEXT IDC_EDIT_LUAPATH,7,16,256,14,ES_AUTOHSCROLL
|
||||
EDITTEXT IDC_LUACONSOLE,7,61,256,81,ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | WS_VSCROLL
|
||||
LTEXT "Output Console",IDC_STATIC,7,51,51,8
|
||||
LTEXT "Script File",IDC_STATIC,7,7,32,8
|
||||
PUSHBUTTON "Edit",IDC_BUTTON_LUAEDIT,58,31,46,16
|
||||
EDITTEXT IDC_EDIT_LUAARGS,47,50,216,14,ES_AUTOHSCROLL
|
||||
EDITTEXT IDC_LUACONSOLE,7,80,256,60,ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | WS_VSCROLL
|
||||
LTEXT "Output Console:",IDC_STATIC,7,70,56,8
|
||||
LTEXT "Script File:",IDC_STATIC,7,7,36,8
|
||||
LTEXT "Arugments:",IDC_STATIC,7,52,40,8
|
||||
PUSHBUTTON "Edit",IDC_BUTTON_LUAEDIT,58,31,46,16
|
||||
END
|
||||
|
||||
VIDEOCONFIG DIALOGEX 65520, 76, 384, 296
|
||||
|
@ -1935,7 +1938,8 @@ IDB_TE_ARROW BITMAP "res/te_arrow.bmp"
|
|||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
|
|
|
@ -467,6 +467,7 @@
|
|||
#define IDC_BUTTON_LUAEDIT 1253
|
||||
#define IDC_LUACONSOLE_CLEAR 1254
|
||||
#define IDC_LUACONSOLE_CHOOSEFONT 1255
|
||||
#define IDC_EDIT_LUAARGS 1256
|
||||
#define MENU_NETWORK 40040
|
||||
#define MENU_PALETTE 40041
|
||||
#define MENU_SOUND 40042
|
||||
|
@ -779,7 +780,7 @@
|
|||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 160
|
||||
#define _APS_NEXT_COMMAND_VALUE 40403
|
||||
#define _APS_NEXT_CONTROL_VALUE 1256
|
||||
#define _APS_NEXT_CONTROL_VALUE 1257
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -65,7 +65,7 @@ void CallRegisteredLuaLoadFunctions(int savestateNumber, const LuaSaveData& save
|
|||
// Just forward function declarations
|
||||
|
||||
void FCEU_LuaFrameBoundary();
|
||||
int FCEU_LoadLuaCode(const char *filename);
|
||||
int FCEU_LoadLuaCode(const char *filename, const char *arg=NULL);
|
||||
void FCEU_ReloadLuaCode();
|
||||
void FCEU_LuaStop();
|
||||
int FCEU_LuaRunning();
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <vector>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __linux
|
||||
|
@ -3049,6 +3049,17 @@ static int gui_parsecolor(lua_State *L)
|
|||
}
|
||||
|
||||
|
||||
// gui.savescreenshot()
|
||||
//
|
||||
// Causes FCEUX to write a screenshot to a file as if the user pressed the associated hotkey.
|
||||
//
|
||||
// Unconditionally retrns 1; any failure in taking a screenshot would be reported on-screen
|
||||
// from the function ReallySnap().
|
||||
static int gui_savescreenshot(lua_State *L) {
|
||||
FCEUI_SaveSnapshot();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// gui.gdscreenshot()
|
||||
//
|
||||
// Returns a screen shot as a string in gd's v1 file format.
|
||||
|
@ -4425,6 +4436,7 @@ static const struct luaL_reg guilib[] = {
|
|||
{"box", gui_box},
|
||||
{"text", gui_text},
|
||||
|
||||
{"savescreenshot", gui_savescreenshot},
|
||||
{"gdscreenshot", gui_gdscreenshot},
|
||||
{"gdoverlay", gui_gdoverlay},
|
||||
{"opacity", gui_setopacity},
|
||||
|
@ -4524,7 +4536,7 @@ void FCEU_LuaFrameBoundary() {
|
|||
*
|
||||
* Returns true on success, false on failure.
|
||||
*/
|
||||
int FCEU_LoadLuaCode(const char *filename) {
|
||||
int FCEU_LoadLuaCode(const char *filename, const char *arg) {
|
||||
if (filename != luaScriptName)
|
||||
{
|
||||
if (luaScriptName) free(luaScriptName);
|
||||
|
@ -4569,6 +4581,16 @@ int FCEU_LoadLuaCode(const char *filename) {
|
|||
lua_register(L, "SHIFT", bit_bshift_emulua);
|
||||
lua_register(L, "BIT", bitbit);
|
||||
|
||||
if (arg)
|
||||
{
|
||||
luaL_Buffer b;
|
||||
luaL_buffinit(L, &b);
|
||||
luaL_addstring(&b, arg);
|
||||
luaL_pushresult(&b);
|
||||
|
||||
lua_setglobal(L, "arg");
|
||||
}
|
||||
|
||||
luabitop_validate(L);
|
||||
|
||||
// push arrays for storing hook functions in
|
||||
|
|
Loading…
Reference in New Issue