Files
SourMesen ad0a1b9849 Lua: Misc. fixes & improvements (#250)
-Fixed getAccessCounters documentation (swapped param order)
-Fixed file watcher not being disabled properly when closing the script window, causing the script to run if changed on the disk, even if the script window is closed
-Prevent file watcher from triggering from writes done by the script window itself (which caused the script to be reloaded 2 or 3 times in a row)
-Fixed UI freezes when using emu.log() on a large table
-Fixed crash when 100k character limit (in the last 500 lines) for script log was reached (out of bounds read/write)
-Added "fps" value to "getState"
-Slightly improved getAccessCounters/getCdlData performance
-Added a new drawPixels API to improve performance when a script needs to draw a lot of individual pixels
2026-08-10 22:42:34 +09:00

121 lines
3.4 KiB
C++

#pragma once
#include "pch.h"
#include "Shared/CpuType.h"
#include "Shared/SettingTypes.h"
#include "Shared/MemoryType.h"
struct lua_State;
class ScriptingContext;
class Debugger;
class Emulator;
class MemoryDumper;
class DebugHud;
class BaseVideoFilter;
class Serializer;
class LuaApi
{
public:
static void SetContext(ScriptingContext* context);
static int GetLibrary(lua_State* lua);
static void LuaPushIntValue(lua_State* lua, string name, int value);
static string SerializeTable(lua_State* lua);
static DebugHud* GetHud();
static int SelectDrawSurface(lua_State* lua);
static int GetMemorySize(lua_State* lua);
static int ReadMemory(lua_State* lua);
static int WriteMemory(lua_State* lua);
static int ReadMemory16(lua_State* lua);
static int WriteMemory16(lua_State* lua);
static int ReadMemory32(lua_State* lua);
static int WriteMemory32(lua_State* lua);
static int GetLabelAddress(lua_State* lua);
static int ConvertAddress(lua_State* lua);
static int RegisterMemoryCallback(lua_State* lua);
static int UnregisterMemoryCallback(lua_State* lua);
static int RegisterEventCallback(lua_State* lua);
static int UnregisterEventCallback(lua_State* lua);
static int MeasureString(lua_State* lua);
static int DrawString(lua_State* lua);
static int DrawLine(lua_State* lua);
static int DrawPixel(lua_State* lua);
static int DrawPixels(lua_State* lua);
static int DrawRectangle(lua_State* lua);
static int ClearScreen(lua_State* lua);
static int GetScreenSize(lua_State* lua);
static int GetDrawSurfaceSize(lua_State* lua);
static int GetScreenBuffer(lua_State* lua);
static int SetScreenBuffer(lua_State* lua);
static int GetPixel(lua_State* lua);
static int GetMouseState(lua_State* lua);
static int Log(lua_State* lua);
static int DisplayMessage(lua_State* lua);
static int Reset(lua_State* lua);
static int Stop(lua_State* lua);
static int BreakExecution(lua_State* lua);
static int Resume(lua_State* lua);
static int Step(lua_State* lua);
static int Rewind(lua_State* lua);
static int TakeScreenshot(lua_State* lua);
static int CreateSavestate(lua_State* lua);
static int LoadSavestate(lua_State* lua);
static int IsKeyPressed(lua_State* lua);
static int GetPressedKeys(lua_State* lua);
static int GetInput(lua_State* lua);
static int SetInput(lua_State* lua);
static int AddCheat(lua_State* lua);
static int ClearCheats(lua_State* lua);
static int GetScriptDataFolder(lua_State* lua);
static int GetRomInfo(lua_State* lua);
static int GetLogWindowLog(lua_State* lua);
static void GenerateStateTable(Serializer& s, lua_State* lua);
static void ReadStateTable(Serializer& s, lua_State* lua);
static int GetCpuCycleCount(lua_State* lua);
static int GetMasterClock(lua_State* lua);
static int GetState(lua_State* lua);
static int GetCpuState(lua_State* lua);
static int SetState(lua_State* lua);
static int SetCpuState(lua_State* lua);
static int GetAccessCounters(lua_State* lua);
static int ResetAccessCounters(lua_State* lua);
static int GetCdlData(lua_State* lua);
private:
static FrameInfo InternalGetScreenSize();
static Emulator* _emu;
static Debugger* _debugger;
static MemoryDumper* _memoryDumper;
static ScriptingContext* _context;
static Serializer _serializer;
static std::pair<unique_ptr<BaseVideoFilter>, FrameInfo> GetRenderedFrame();
template<typename T> static void GenerateEnumDefinition(lua_State* lua, string enumName, unordered_set<T> excludedValues = {});
};