GodMode9/arm9/source/lua/gm9lua.h
Tage Mellemstrand 584b68b7b1
Add support for reading and writing to I2C devices from lua (#934)
* Add i2c read support to lua

* Add i2c write support to lua

With memory permissions before write

* Adjust i2c write

* Fix inverted id check, better permissions

* Change write to not return anything on success

* Add some documentation for lua i2c

* Change write length from 1024 to 64

* Add whitelist for i2c writing

* Move i2c module into preload

* Add registers and bitmasks for mcu

Add documentation to lua-doc

* Fix missing column divider in lua-doc

* Add ~= 0 then to lua example

* Add some more registers
2026-03-25 23:18:03 +01:00

51 lines
2.0 KiB
C

#pragma once
#include "common.h"
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "scripting.h"
// this should probably go in filesys/fsutil.h
#define RECURSIVE (1UL<<11)
#define TO_EMUNAND (1UL<<12)
#define LEGIT (1UL<<13)
#define FIND_FIRST (1UL<<14)
#define INCLUDE_DIRS (1UL<<15)
#define EXPLORER (1UL<<16)
#define ENCRYPTED (1UL<<17)
#define SIG_CHECK (1UL<<18)
#define USE_LOCALE (1UL<<19)
#define FLAGS_STR "no_cancel", "silent", "calc_sha", "sha1", "skip", "overwrite", "append", "all", "recursive", "to_emunand", "legit", "first", "include_dirs", "explorer", "encrypted", "sig_check", "use_locale"
#define FLAGS_CONSTS NO_CANCEL, SILENT, CALC_SHA, USE_SHA1, SKIP_ALL, OVERWRITE_ALL, APPEND_ALL, ASK_ALL, RECURSIVE, TO_EMUNAND, LEGIT, FIND_FIRST, INCLUDE_DIRS, EXPLORER, ENCRYPTED, SIG_CHECK, USE_LOCALE
#define FLAGS_COUNT 17
#define LUASCRIPT_EXT "lua"
#define LUASCRIPT_MAX_SIZE STD_BUFFER_SIZE
// taken from arm9/source/utils/scripting.c
#define _VAR_CNT_LEN 256
#ifndef NO_LUA
static inline void CheckLuaArgCount(lua_State* L, int argcount, const char* cmd) {
int args = lua_gettop(L);
if (args != argcount) {
luaL_error(L, "bad number of arguments passed to '%s' (expected %d, got %d)", cmd, argcount, args);
}
}
// this is used in cases where a function accepts a flags table or something else
static inline bool CheckLuaArgCountPlusExtra(lua_State* L, int argcount, const char* cmd) {
int args = lua_gettop(L);
if (args != argcount && args != argcount + 1) {
luaL_error(L, "bad number of arguments passed to '%s' (expected %d or %d, got %d)", cmd, argcount, argcount + 1, args);
}
return args == argcount + 1;
}
int LoadLuaFile(lua_State* L, const char* filename);
u32 GetFlagsFromTable(lua_State* L, int pos, u32 flags_ext_starter, u32 allowed_flags);
void CheckWritePermissionsLuaError(lua_State* L, const char* path);
void SetWritePermissionsLuaError(lua_State* L, u32 perm);
#endif
bool ExecuteLuaScript(const char* path_script);