smlua use lot and lvt names rather than an index

This commit is contained in:
Isaac0-dev 2025-03-10 12:18:11 +10:00
parent 7cdad52fb8
commit 04ea4d6ad4
10 changed files with 203 additions and 10 deletions

View file

@ -46,6 +46,11 @@ $[INCLUDES]
#include "include/object_fields.h"
$[BODY]
const char *smlua_get_lot_name(u16 lot) {
assert(smlua_valid_lot(lot)); // if this is false, it means there's an invalid lot somewhere
return sLuaLotNames[lot];
}
struct LuaObjectField* smlua_get_object_field_autogen(u16 lot, const char* key) {
struct LuaObjectTable* ot = &sLuaObjectAutogenTable[lot - LOT_AUTOGEN_MIN - 1];
return smlua_get_object_field_from_ot(ot, key);
@ -59,6 +64,7 @@ h_template = """/* THIS FILE IS AUTOGENERATED */
#define SMLUA_COBJECT_AUTOGEN_H
$[BODY]
const char *smlua_get_lot_name(u16 lot);
struct LuaObjectField* smlua_get_object_field_autogen(u16 lot, const char* key);
#endif
@ -581,7 +587,23 @@ def build_body(parsed):
obj_table_built += obj_table_row_built
obj_table_built += '};\n'
return built + obj_table_built
lot_names = '\nconst char *sLuaLotNames[] = {\n'
for type_name in VEC_TYPES.keys():
lot_names += f'\t[LOT_{type_name.upper()}] = "{type_name}",\n'
lot_names += f'\t[LOT_ARRAY] = "Array",\n'
lot_names += f'\t[LOT_POINTER] = "Pointer",\n'
lot_names += f'\t[LOT_MAX] = "Max",\n'
lot_names += '\n'
for struct in parsed:
sid = struct['identifier']
if sid in exclude_structs:
continue
lot_names += f'\t[LOT_{sid.upper()}] = "{sid}",\n'
lot_names += '};\n'
return built + obj_table_built + lot_names
def build_lot_enum():
s = ''

View file

@ -13677,7 +13677,7 @@ SPTASK_STATE_FINISHED = 3
SPTASK_STATE_FINISHED_DP = 4
--- @type integer
MAX_VERSION_LENGTH = 32
MAX_VERSION_LENGTH = 128
--- @type integer
MINOR_VERSION_NUMBER = 1

View file

@ -9743,7 +9743,7 @@ end
--- @param index integer
--- @return integer
--- Gets the water level in an area
--- Gets the water level in an area corresponding to `index` (0-indexed)
function get_water_level(index)
-- ...
end
@ -9944,7 +9944,7 @@ end
--- @param index integer
--- @param height integer
--- @param sync boolean
--- Sets the water level in an area
--- Sets the water level in an area corresponding to `index` (0-indexed)
function set_water_level(index, height, sync)
-- ...
end

View file

@ -1106,7 +1106,7 @@ Gets the volume level of sound effects
## [get_water_level](#get_water_level)
### Description
Gets the water level in an area
Gets the water level in an area corresponding to `index` (0-indexed)
### Lua Example
`local integerValue = get_water_level(index)`
@ -1798,7 +1798,7 @@ Sets the volume level of sound effects
## [set_water_level](#set_water_level)
### Description
Sets the water level in an area
Sets the water level in an area corresponding to `index` (0-indexed)
### Lua Example
`set_water_level(index, height, sync)`

View file

@ -68,6 +68,49 @@ bool smlua_valid_lvt(u16 lvt) {
return (lvt < LVT_MAX);
}
const char *sLuaLvtNames[] = {
[LVT_BOOL] = "bool",
[LVT_BOOL_P] = "bool Pointer",
[LVT_U8] = "u8",
[LVT_U8_P] = "u8 Pointer",
[LVT_U16] = "u16",
[LVT_U16_P] = "u16 Pointer",
[LVT_U32] = "u32",
[LVT_U32_P] = "u32 Pointer",
[LVT_S8] = "s8",
[LVT_S8_P] = "s8 Pointer",
[LVT_S16] = "s16",
[LVT_S16_P] = "s16 Pointer",
[LVT_S32] = "s32",
[LVT_S32_P] = "s32 Pointer",
[LVT_F32] = "f32",
[LVT_F32_P] = "f32 Pointer",
[LVT_U64] = "u64",
[LVT_U64_P] = "u64 Pointer",
[LVT_COBJECT] = "CObject",
[LVT_COBJECT_P] = "CObject Pointer",
[LVT_STRING] = "string",
[LVT_STRING_P] = "string Pointer",
[LVT_BEHAVIORSCRIPT] = "BehaviorScript",
[LVT_BEHAVIORSCRIPT_P] = "BehaviorScript Pointer",
[LVT_OBJECTANIMPOINTER] = "ObjectAnimPointer",
[LVT_OBJECTANIMPOINTER_P] = "ObjectAnimPointer Pointer",
[LVT_COLLISION] = "Collision",
[LVT_COLLISION_P] = "Collision Pointer",
[LVT_LEVELSCRIPT] = "LevelScript",
[LVT_LEVELSCRIPT_P] = "LevelScript Pointer",
[LVT_TRAJECTORY] = "Trajectory",
[LVT_TRAJECTORY_P] = "Trajectory Pointer",
[LVT_LUAFUNCTION] = "LuaFunction",
[LVT_POINTER] = "Pointer",
[LVT_MAX] = "Max",
};
const char *smlua_get_lvt_name(u16 lvt) {
assert(smlua_valid_lvt(lvt)); // if this is false, it means there's an invalid lvt somewhere
return sLuaLvtNames[lvt];
}
//////////////////
// obj behavior //
//////////////////
@ -500,7 +543,7 @@ static int smlua__get_field(lua_State* L) {
data = smlua_get_custom_field(L, lot, 2);
}
if (data == NULL) {
LOG_LUA_LINE("_get_field on invalid key '%s', lot '%d'", key, lot);
LOG_LUA_LINE("_get_field on invalid key '%s', lot '%s'", key, smlua_get_lot_name(lot));
return 0;
}

View file

@ -76,6 +76,7 @@ extern int gSmLuaCPointerMetatable;
bool smlua_valid_lot(u16 lot);
bool smlua_valid_lvt(u16 lvt);
const char *smlua_get_lvt_name(u16 lvt);
struct LuaObjectField* smlua_get_object_field_from_ot(struct LuaObjectTable* ot, const char* key);
struct LuaObjectField* smlua_get_object_field(u16 lot, const char* key);
struct LuaObjectField* smlua_get_custom_field(lua_State* L, u32 lot, int keyIndex);

View file

@ -2889,6 +2889,132 @@ struct LuaObjectTable sLuaObjectAutogenTable[LOT_AUTOGEN_MAX - LOT_AUTOGEN_MIN]
{ LOT_STRUCT802A1230, sstruct802A1230Fields, LUA_STRUCT802_A1230_FIELD_COUNT },
};
const char *sLuaLotNames[] = {
[LOT_VEC2F] = "Vec2f",
[LOT_VEC3F] = "Vec3f",
[LOT_VEC4F] = "Vec4f",
[LOT_VEC3S] = "Vec3s",
[LOT_VEC4S] = "Vec4s",
[LOT_MAT4] = "Mat4",
[LOT_COLOR] = "Color",
[LOT_ARRAY] = "Array",
[LOT_POINTER] = "Pointer",
[LOT_MAX] = "Max",
[LOT_ANIMINFO] = "AnimInfo",
[LOT_ANIMATION] = "Animation",
[LOT_ANIMATIONTABLE] = "AnimationTable",
[LOT_AREA] = "Area",
[LOT_BEHAVIORDIALOGS] = "BehaviorDialogs",
[LOT_BEHAVIORTRAJECTORIES] = "BehaviorTrajectories",
[LOT_BEHAVIORVALUES] = "BehaviorValues",
[LOT_BULLYCOLLISIONDATA] = "BullyCollisionData",
[LOT_CAMERA] = "Camera",
[LOT_CAMERAFOVSTATUS] = "CameraFOVStatus",
[LOT_CAMERAOVERRIDE] = "CameraOverride",
[LOT_CAMERASTOREDINFO] = "CameraStoredInfo",
[LOT_CAMERATRIGGER] = "CameraTrigger",
[LOT_CHAINSEGMENT] = "ChainSegment",
[LOT_CHARACTER] = "Character",
[LOT_CONTROLLER] = "Controller",
[LOT_CUSTOMLEVELINFO] = "CustomLevelInfo",
[LOT_CUTSCENE] = "Cutscene",
[LOT_CUTSCENESPLINEPOINT] = "CutsceneSplinePoint",
[LOT_CUTSCENEVARIABLE] = "CutsceneVariable",
[LOT_DATETIME] = "DateTime",
[LOT_DISPLAYLISTNODE] = "DisplayListNode",
[LOT_DJUICOLOR] = "DjuiColor",
[LOT_DJUIINTERACTABLETHEME] = "DjuiInteractableTheme",
[LOT_DJUIPANELTHEME] = "DjuiPanelTheme",
[LOT_DJUITHEME] = "DjuiTheme",
[LOT_DJUITHREEPANELTHEME] = "DjuiThreePanelTheme",
[LOT_EXCLAMATIONBOXCONTENT] = "ExclamationBoxContent",
[LOT_FIRSTPERSONCAMERA] = "FirstPersonCamera",
[LOT_FLOORGEOMETRY] = "FloorGeometry",
[LOT_FNGRAPHNODE] = "FnGraphNode",
[LOT_GFX] = "Gfx",
[LOT_GLOBALOBJECTANIMATIONS] = "GlobalObjectAnimations",
[LOT_GLOBALOBJECTCOLLISIONDATA] = "GlobalObjectCollisionData",
[LOT_GLOBALTEXTURES] = "GlobalTextures",
[LOT_GRAPHNODE] = "GraphNode",
[LOT_GRAPHNODEANIMATEDPART] = "GraphNodeAnimatedPart",
[LOT_GRAPHNODEBACKGROUND] = "GraphNodeBackground",
[LOT_GRAPHNODEBILLBOARD] = "GraphNodeBillboard",
[LOT_GRAPHNODECAMERA] = "GraphNodeCamera",
[LOT_GRAPHNODECULLINGRADIUS] = "GraphNodeCullingRadius",
[LOT_GRAPHNODEDISPLAYLIST] = "GraphNodeDisplayList",
[LOT_GRAPHNODEGENERATED] = "GraphNodeGenerated",
[LOT_GRAPHNODEHELDOBJECT] = "GraphNodeHeldObject",
[LOT_GRAPHNODELEVELOFDETAIL] = "GraphNodeLevelOfDetail",
[LOT_GRAPHNODEMASTERLIST] = "GraphNodeMasterList",
[LOT_GRAPHNODEOBJECT] = "GraphNodeObject",
[LOT_GRAPHNODEOBJECTPARENT] = "GraphNodeObjectParent",
[LOT_GRAPHNODEORTHOPROJECTION] = "GraphNodeOrthoProjection",
[LOT_GRAPHNODEPERSPECTIVE] = "GraphNodePerspective",
[LOT_GRAPHNODEROTATION] = "GraphNodeRotation",
[LOT_GRAPHNODESCALE] = "GraphNodeScale",
[LOT_GRAPHNODESHADOW] = "GraphNodeShadow",
[LOT_GRAPHNODESTART] = "GraphNodeStart",
[LOT_GRAPHNODESWITCHCASE] = "GraphNodeSwitchCase",
[LOT_GRAPHNODETRANSLATION] = "GraphNodeTranslation",
[LOT_GRAPHNODETRANSLATIONROTATION] = "GraphNodeTranslationRotation",
[LOT_GRAPHNODE_802A45E4] = "GraphNode_802A45E4",
[LOT_HANDHELDSHAKEPOINT] = "HandheldShakePoint",
[LOT_HUDUTILSROTATION] = "HudUtilsRotation",
[LOT_INSTANTWARP] = "InstantWarp",
[LOT_LAKITUSTATE] = "LakituState",
[LOT_LEVELVALUES] = "LevelValues",
[LOT_LINEARTRANSITIONPOINT] = "LinearTransitionPoint",
[LOT_MARIOANIMATION] = "MarioAnimation",
[LOT_MARIOBODYSTATE] = "MarioBodyState",
[LOT_MARIOSTATE] = "MarioState",
[LOT_MOD] = "Mod",
[LOT_MODAUDIO] = "ModAudio",
[LOT_MODAUDIOSAMPLECOPIES] = "ModAudioSampleCopies",
[LOT_MODFILE] = "ModFile",
[LOT_MODETRANSITIONINFO] = "ModeTransitionInfo",
[LOT_NAMETAGSSETTINGS] = "NametagsSettings",
[LOT_NETWORKPLAYER] = "NetworkPlayer",
[LOT_OBJECT] = "Object",
[LOT_OBJECTHITBOX] = "ObjectHitbox",
[LOT_OBJECTNODE] = "ObjectNode",
[LOT_OBJECTWARPNODE] = "ObjectWarpNode",
[LOT_OFFSETSIZEPAIR] = "OffsetSizePair",
[LOT_PAINTING] = "Painting",
[LOT_PAINTINGMESHVERTEX] = "PaintingMeshVertex",
[LOT_PAINTINGVALUES] = "PaintingValues",
[LOT_PARALLELTRACKINGPOINT] = "ParallelTrackingPoint",
[LOT_PLAYERCAMERASTATE] = "PlayerCameraState",
[LOT_PLAYERGEOMETRY] = "PlayerGeometry",
[LOT_PLAYERPALETTE] = "PlayerPalette",
[LOT_RAYINTERSECTIONINFO] = "RayIntersectionInfo",
[LOT_SERVERSETTINGS] = "ServerSettings",
[LOT_SOUNDSTATE] = "SoundState",
[LOT_SPAWNINFO] = "SpawnInfo",
[LOT_SPAWNPARTICLESINFO] = "SpawnParticlesInfo",
[LOT_STARPOSITIONS] = "StarPositions",
[LOT_STARSNEEDEDFORDIALOG] = "StarsNeededForDialog",
[LOT_STRUCT802A272C] = "Struct802A272C",
[LOT_SURFACE] = "Surface",
[LOT_TEXTUREINFO] = "TextureInfo",
[LOT_TRANSITIONINFO] = "TransitionInfo",
[LOT_VTX] = "Vtx",
[LOT_VTX_INTERP] = "Vtx_Interp",
[LOT_WALLCOLLISIONDATA] = "WallCollisionData",
[LOT_WARPNODE] = "WarpNode",
[LOT_WARPTRANSITION] = "WarpTransition",
[LOT_WARPTRANSITIONDATA] = "WarpTransitionData",
[LOT_WATERDROPLETPARAMS] = "WaterDropletParams",
[LOT_WAYPOINT] = "Waypoint",
[LOT_WHIRLPOOL] = "Whirlpool",
[LOT_STRUCT802A1230] = "struct802A1230",
};
const char *smlua_get_lot_name(u16 lot) {
assert(smlua_valid_lot(lot)); // if this is false, it means there's an invalid lot somewhere
return sLuaLotNames[lot];
}
struct LuaObjectField* smlua_get_object_field_autogen(u16 lot, const char* key) {
struct LuaObjectTable* ot = &sLuaObjectAutogenTable[lot - LOT_AUTOGEN_MIN - 1];
return smlua_get_object_field_from_ot(ot, key);

View file

@ -129,6 +129,7 @@ enum LuaObjectAutogenType {
LOT_AUTOGEN_MAX,
};
const char *smlua_get_lot_name(u16 lot);
struct LuaObjectField* smlua_get_object_field_autogen(u16 lot, const char* key);
#endif

View file

@ -4729,5 +4729,5 @@ char gSmluaConstants[] = ""
"VERSION_TEXT='v'\n"
"VERSION_NUMBER=39\n"
"MINOR_VERSION_NUMBER=1\n"
"MAX_VERSION_LENGTH=32\n"
"MAX_VERSION_LENGTH=128\n"
;

View file

@ -159,7 +159,7 @@ void* smlua_to_cobject(lua_State* L, int index, u16 lot) {
CObject *cobject = luaL_checkudata(L, index, "CObject");
if (lot != cobject->lot) {
LOG_LUA_LINE("smlua_to_cobject received improper LOT. Expected '%d', received '%d'", lot, cobject->lot);
LOG_LUA_LINE("smlua_to_cobject received improper LOT. Expected '%s', received '%s'", smlua_get_lot_name(lot), smlua_get_lot_name(cobject->lot));
gSmLuaConvertSuccess = false;
return NULL;
}
@ -185,7 +185,7 @@ void* smlua_to_cpointer(lua_State* L, int index, u16 lvt) {
CPointer *cpointer = luaL_checkudata(L, index, "CPointer");
if (lvt != cpointer->lvt) {
LOG_LUA_LINE("smlua_to_cpointer received improper LOT. Expected '%d', received '%d'", lvt, cpointer->lvt);
LOG_LUA_LINE("smlua_to_cpointer received improper LOT. Expected '%s', received '%s'", smlua_get_lvt_name(lvt), smlua_get_lvt_name(cpointer->lvt));
gSmLuaConvertSuccess = false;
return NULL;
}