autogen array implementation

arrays are pushed to Lua via tables
This commit is contained in:
Isaac0-dev 2025-02-12 17:38:38 +10:00
parent 14101ce10c
commit ff83d6a037
13 changed files with 2531 additions and 2407 deletions

View file

@ -1,10 +1,21 @@
import os
import re
from vec_types import *
usf_types = ['u8', 'u16', 'u32', 'u64', 's8', 's16', 's32', 's64', 'f32']
vec_types = list(VEC_TYPES.keys())
typedef_pointers = ['BehaviorScript', 'ObjectAnimPointer', 'Collision', 'LevelScript', 'Trajectory']
type_mappings = {
'char': 's8',
'short': 's16',
'int': 's32',
'long': 's32',
'long long': 's64',
'float': 'f32',
'double': 'f64',
}
exclude_structs = [
'SPTask',
'VblankHandler',
@ -13,10 +24,23 @@ exclude_structs = [
'UnusedArea28',
]
def extract_integer_datatype(c_type):
c_type = c_type.strip().lower()
c_type = re.sub(r'\*|\[.*?\]', '', c_type)
if 'unsigned' in c_type:
base_type = c_type.replace('unsigned', '').strip()
base_type_internal = type_mappings.get(base_type, None)
if base_type_internal: return 'u' + base_type_internal[1:]
elif 'signed' in c_type or c_type in type_mappings:
base_type = c_type.replace('signed', '').strip()
base_type_internal = type_mappings.get(base_type, None)
if base_type_internal: return base_type_internal
return None
def get_path(p):
return os.path.dirname(os.path.realpath(__file__)) + '/../' + p
def translate_type_to_lvt(ptype):
def translate_type_to_lvt(ptype, allowArrays=False):
pointerLvl = 0
if ptype == "char":
@ -28,6 +52,10 @@ def translate_type_to_lvt(ptype):
if ("char" in ptype and "[" in ptype):
return "LVT_STRING"
# Remove array symbols so they can be identified
if allowArrays and re.search(r'\[([^\]]+)\]', ptype):
ptype = re.sub(r'\[[^\]]*\]', '', ptype).strip()
if "[" in ptype or "{" in ptype:
return "LVT_???"
@ -61,6 +89,14 @@ def translate_type_to_lvt(ptype):
return "LVT_" + ptype.upper() + "_P"
return "LVT_" + ptype.upper()
type = extract_integer_datatype(ptype)
if type:
if pointerLvl > 1:
return "LVT_???"
if pointerLvl == 1:
return "LVT_" + ptype.upper() + "_P"
return "LVT_" + ptype.upper()
if ptype in vec_types:
if pointerLvl > 1:
return "LVT_???"
@ -92,9 +128,9 @@ def translate_type_to_lvt(ptype):
return "LVT_???"
def translate_type_to_lot(ptype):
def translate_type_to_lot(ptype, allowArrays=True):
pointerLvl = 0
lvt = translate_type_to_lvt(ptype)
lvt = translate_type_to_lvt(ptype, allowArrays=allowArrays)
if ptype == 'void':
return 'LOT_NONE'
@ -105,6 +141,10 @@ def translate_type_to_lot(ptype):
if ptype == 'char*' or ('char' in ptype and '[' in ptype):
return 'LOT_NONE'
# Remove array symbols so they can be identified
if allowArrays and re.search(r'\[([^\]]+)\]', ptype):
ptype = re.sub(r'\[[^\]]*\]', '', ptype).strip()
if 'const ' in ptype:
ptype = ptype.replace('const ', '')
@ -156,10 +196,6 @@ def translate_type_to_lot(ptype):
return 'LOT_???'
def translate_type_to_lua(ptype):
if ptype.startswith('struct '):
ptype = ptype.split(' ')[1].replace('*', '')
return ptype, 'structs.md#%s' % ptype
if ptype == 'const char*':
return '`string`', None
@ -168,6 +204,16 @@ def translate_type_to_lua(ptype):
ptype = ptype.replace('const ', '')
# Detect arrays
if re.search(r'\[([^\]]+)\]', ptype):
ptype = re.sub(r'\[[^\]]*\]', '', ptype).strip()
s = '`Array` <%s>' % translate_type_to_lua(ptype)[0]
return s, None
if ptype.startswith('struct '):
ptype = ptype.split(' ')[1].replace('*', '')
return ptype, 'structs.md#%s' % ptype
if 'Vec3' in ptype:
return ptype, 'structs.md#%s' % ptype

View file

@ -73,6 +73,9 @@ pretend_find = [
seen_constants = []
totalConstants = 0
verbose = len(sys.argv) > 1 and (sys.argv[1] == "-v" or sys.argv[1] == "--verbose")
overrideConstant = {
'VERSION_REGION': '"US"',
}
############################################################################
@ -113,6 +116,9 @@ def allowed_identifier(filename, ident):
if re.search(include, ident) != None:
return True
return False
if ident in overrideConstant:
return False
return True
@ -218,6 +224,8 @@ def process_files():
files = sorted(in_files, key=lambda d: d.split('/')[-1])
for f in files:
processed_files.append(process_file(f))
for key, item in overrideConstant.items():
processed_files[0]['constants'].append([key, item])
return processed_files
############################################################################

View file

@ -144,13 +144,13 @@ override_allowed_structs = {
sLuaManuallyDefinedStructs = [{
'path': 'n/a',
'structs': [
'struct %s { %s }' % (
*['struct %s { %s }' % (
type_name,
' '.join([
'%s %s;' % (vec_type['field_c_type'], lua_field)
for lua_field in vec_type['fields_mapping'].keys()
])
) for type_name, vec_type in VEC_TYPES.items()
) for type_name, vec_type in VEC_TYPES.items()]
]
}]
@ -342,7 +342,7 @@ def output_fuzz_struct(struct):
s_out += ' local funcs = {\n'
for field in struct['fields']:
fid, ftype, fimmutable, lvt, lot = get_struct_field_info(struct, field)
fid, ftype, fimmutable, lvt, lot, size = get_struct_field_info(struct, field)
if fimmutable == 'true':
continue
if sid in override_field_invisible:
@ -409,7 +409,7 @@ def build_vec_types():
]
sorted_fields_with_order = sorted(combined_fields, key=lambda x: x[1]) # sort alphabetically
for original_index, lua_field in sorted_fields_with_order:
s += ' { "%s", LVT_%s, sizeof(%s) * %d, false, LOT_NONE },\n' % (lua_field, field_c_type.upper(), field_c_type, original_index)
s += ' { "%s", LVT_%s, sizeof(%s) * %d, false, LOT_NONE, 1, sizeof(%s) },\n' % (lua_field, field_c_type.upper(), field_c_type, original_index, field_c_type)
s += '};\n\n'
@ -433,6 +433,7 @@ def get_struct_field_info(struct, field):
sid = struct['identifier']
fid = field['identifier']
ftype = field['type']
size = 1
if sid in override_field_names and fid in override_field_names[sid]:
fid = override_field_names[sid][fid]
@ -440,8 +441,8 @@ def get_struct_field_info(struct, field):
if sid in override_field_types and fid in override_field_types[sid]:
ftype = override_field_types[sid][fid]
lvt = translate_type_to_lvt(ftype)
lot = translate_type_to_lot(ftype)
lvt = translate_type_to_lvt(ftype, allowArrays=True)
lot = translate_type_to_lot(ftype, allowArrays=True)
fimmutable = str(lvt == 'LVT_COBJECT' or 'const ' in ftype).lower()
if lvt.startswith('LVT_') and lvt.endswith('_P') and 'OBJECT' not in lvt and 'COLLISION' not in lvt and 'TRAJECTORY' not in lvt:
fimmutable = 'true'
@ -454,7 +455,18 @@ def get_struct_field_info(struct, field):
if fid in override_field_mutable[sid] or '*' in override_field_mutable[sid]:
fimmutable = 'false'
return fid, ftype, fimmutable, lvt, lot
if not ('char' in ftype and '[' in ftype):
array_match = re.search(r'\[([^\]]+)\]', ftype)
if array_match:
array_size = array_match.group(1).strip()
if array_size.isdigit():
size = int(array_size)
elif array_size.startswith("0x") and all(c in "0123456789abcdef" for c in array_size[2:]):
size = int(array_size, 16)
else:
lvt, lot = 'LVT_???', "LOT_???" # array size not provided, so not supported
return fid, ftype, fimmutable, lvt, lot, size
def build_struct(struct):
# debug print out lua fuzz functions
@ -466,7 +478,10 @@ def build_struct(struct):
# build up table and track column width
field_table = []
for field in struct['fields']:
fid, ftype, fimmutable, lvt, lot = get_struct_field_info(struct, field)
fid, ftype, fimmutable, lvt, lot, size = get_struct_field_info(struct, field)
if re.search(r'\[([^\]]+)\]', ftype):
ftype = re.sub(r'\[[^\]]*\]', '', ftype).strip()
if sid in override_field_invisible:
if fid in override_field_invisible[sid]:
@ -487,7 +502,9 @@ def build_struct(struct):
row.append('%s, ' % lvt )
row.append('offsetof(struct %s, %s), ' % (sid, field['identifier']) )
row.append('%s, ' % fimmutable )
row.append("%s" % lot )
row.append('%s, ' % lot )
row.append('%s, ' % size )
row.append('sizeof(%s)' % ftype )
row.append(endStr )
field_table.append(row)
@ -586,7 +603,7 @@ def doc_struct_index(structs):
return s
def doc_struct_field(struct, field):
fid, ftype, fimmutable, lvt, lot = get_struct_field_info(struct, field)
fid, ftype, fimmutable, lvt, lot, size = get_struct_field_info(struct, field)
sid = struct['identifier']
if sid in override_field_invisible:
@ -679,7 +696,7 @@ def def_struct(struct):
s = '\n--- @class %s\n' % stype
for field in struct['fields']:
fid, ftype, fimmutable, lvt, lot = get_struct_field_info(struct, field)
fid, ftype, fimmutable, lvt, lot, size = get_struct_field_info(struct, field)
if sid in override_field_invisible:
if fid in override_field_invisible[sid]:

View file

@ -324,6 +324,9 @@ INSTANT_WARP_INDEX_STOP = 0x04
--- @type integer
MAX_AREAS = 16
--- @type string
VERSION_REGION = "US"
--- @type integer
WARP_TRANSITION_FADE_FROM_BOWSER = 0x12
@ -12525,17 +12528,5 @@ SM64COOPDX_VERSION = "v1.2.0"
--- @type integer
VERSION_NUMBER = 38
--- @type string
VERSION_REGION = "JP"
--- @type string
VERSION_REGION = "EU"
--- @type string
VERSION_REGION = "SH"
--- @type string
VERSION_REGION = "US"
--- @type string
VERSION_TEXT = "v"

View file

@ -31,6 +31,7 @@
--- @class Area
--- @field public camera Camera
--- @field public dialog Array_integer
--- @field public flags integer
--- @field public index integer
--- @field public instantWarps InstantWarp
@ -48,6 +49,7 @@
--- @field public terrainData Pointer_integer
--- @field public terrainType integer
--- @field public warpNodes ObjectWarpNode
--- @field public whirlpools Array_Whirlpool
--- @class BehaviorDialogs
--- @field public BobombBuddyBob1Dialog DialogId
@ -216,6 +218,8 @@
--- @field public cutscene integer
--- @field public defMode integer
--- @field public doorStatus integer
--- @field public filler31 Array_integer
--- @field public filler3C Array_integer
--- @field public focus Vec3f
--- @field public mode integer
--- @field public mtx Mat4
@ -641,6 +645,7 @@
--- @field public normalY number
--- @field public normalZ number
--- @field public originOffset number
--- @field public unused Array_number
--- @class FnGraphNode
--- @field public node GraphNode
@ -863,6 +868,7 @@
--- @class GraphNodeCullingRadius
--- @field public cullingRadius integer
--- @field public node GraphNode
--- @field public pad1E Array_integer
--- @class GraphNodeDisplayList
--- @field public node GraphNode
@ -961,6 +967,7 @@
--- @class GraphNodeTranslation
--- @field public node GraphNode
--- @field public pad1E Array_integer
--- @field public translation Vec3s
--- @class GraphNodeTranslationRotation
@ -998,6 +1005,9 @@
--- @field public curFocus Vec3f
--- @field public curPos Vec3f
--- @field public defMode integer
--- @field public filler30 Array_integer
--- @field public filler3E Array_integer
--- @field public filler72 Array_integer
--- @field public focHSpeed number
--- @field public focVSpeed number
--- @field public focus Vec3f
@ -1093,6 +1103,7 @@
--- @class MarioAnimation
--- @field public currentAnimAddr Pointer_integer
--- @field public padding Array_integer
--- @field public targetAnim Animation
--- @class MarioBodyState
@ -1101,6 +1112,7 @@
--- @field public capState integer
--- @field public eyeState integer
--- @field public grabPos integer
--- @field public handFootPos Array_Vec3f
--- @field public handState integer
--- @field public headAngle Vec3s
--- @field public headPos Vec3f
@ -1236,6 +1248,7 @@
--- @class ModFile
--- @field public cachedPath string
--- @field public dataHash Array_integer
--- @field public relativePath string
--- @field public wroteBytes integer
@ -1295,6 +1308,7 @@
--- @field public bhvDelayTimer integer
--- @field public bhvStackIndex integer
--- @field public collidedObjInteractTypes integer
--- @field public collidedObjs Array_Object
--- @field public collisionData Pointer_Collision
--- @field public coopFlags integer
--- @field public ctx integer
@ -2109,6 +2123,8 @@
--- @field public yaw number
--- @class PaintingMeshVertex
--- @field public norm Array_integer
--- @field public pos Array_integer
--- @class PaintingValues
--- @field public bob_painting Painting
@ -2292,6 +2308,7 @@
--- @field public offsetY number
--- @field public radius number
--- @field public unused integer
--- @field public walls Array_Surface
--- @field public x number
--- @field public y number
--- @field public z number

View file

@ -87,6 +87,7 @@
- INSTANT_WARP_INDEX_START
- INSTANT_WARP_INDEX_STOP
- MAX_AREAS
- VERSION_REGION
- WARP_TRANSITION_FADE_FROM_BOWSER
- WARP_TRANSITION_FADE_FROM_CIRCLE
- WARP_TRANSITION_FADE_FROM_COLOR
@ -4518,10 +4519,6 @@
- MINOR_VERSION_NUMBER
- SM64COOPDX_VERSION
- VERSION_NUMBER
- VERSION_REGION
- VERSION_REGION
- VERSION_REGION
- VERSION_REGION
- VERSION_TEXT
[:arrow_up_small:](#)

View file

@ -175,6 +175,7 @@
| Field | Type | Access |
| ----- | ---- | ------ |
| camera | [Camera](structs.md#Camera) | |
| dialog | `Array` <`integer`> | |
| flags | `integer` | |
| index | `integer` | |
| instantWarps | [InstantWarp](structs.md#InstantWarp) | |
@ -192,6 +193,7 @@
| terrainData | `Pointer` <`integer`> | read-only |
| terrainType | `integer` | |
| warpNodes | [ObjectWarpNode](structs.md#ObjectWarpNode) | read-only |
| whirlpools | `Array` <Whirlpool> | |
[:arrow_up_small:](#)
@ -395,6 +397,8 @@
| cutscene | `integer` | |
| defMode | `integer` | |
| doorStatus | `integer` | |
| filler31 | `Array` <`integer`> | |
| filler3C | `Array` <`integer`> | |
| focus | [Vec3f](structs.md#Vec3f) | read-only |
| mode | `integer` | |
| mtx | `Mat4` | read-only |
@ -979,6 +983,7 @@
| normalY | `number` | |
| normalZ | `number` | |
| originOffset | `number` | |
| unused | `Array` <`number`> | |
[:arrow_up_small:](#)
@ -1271,6 +1276,7 @@
| ----- | ---- | ------ |
| cullingRadius | `integer` | |
| node | [GraphNode](structs.md#GraphNode) | read-only |
| pad1E | `Array` <`integer`> | |
[:arrow_up_small:](#)
@ -1474,6 +1480,7 @@
| Field | Type | Access |
| ----- | ---- | ------ |
| node | [GraphNode](structs.md#GraphNode) | read-only |
| pad1E | `Array` <`integer`> | |
| translation | [Vec3s](structs.md#Vec3s) | read-only |
[:arrow_up_small:](#)
@ -1553,6 +1560,9 @@
| curFocus | [Vec3f](structs.md#Vec3f) | read-only |
| curPos | [Vec3f](structs.md#Vec3f) | read-only |
| defMode | `integer` | |
| filler30 | `Array` <`integer`> | |
| filler3E | `Array` <`integer`> | |
| filler72 | `Array` <`integer`> | |
| focHSpeed | `number` | |
| focVSpeed | `number` | |
| focus | [Vec3f](structs.md#Vec3f) | read-only |
@ -1669,6 +1679,7 @@
| Field | Type | Access |
| ----- | ---- | ------ |
| currentAnimAddr | `Pointer` <`integer`> | read-only |
| padding | `Array` <`integer`> | |
| targetAnim | [Animation](structs.md#Animation) | |
[:arrow_up_small:](#)
@ -1684,6 +1695,7 @@
| capState | `integer` | |
| eyeState | `integer` | |
| grabPos | `integer` | |
| handFootPos | `Array` <Vec3f> | read-only |
| handState | `integer` | |
| headAngle | [Vec3s](structs.md#Vec3s) | read-only |
| headPos | [Vec3f](structs.md#Vec3f) | read-only |
@ -1879,6 +1891,7 @@
| Field | Type | Access |
| ----- | ---- | ------ |
| cachedPath | `string` | read-only |
| dataHash | `Array` <`integer`> | read-only |
| relativePath | `string` | read-only |
| wroteBytes | `integer` | read-only |
@ -1963,6 +1976,7 @@
| bhvDelayTimer | `integer` | |
| bhvStackIndex | `integer` | read-only |
| collidedObjInteractTypes | `integer` | |
| collidedObjs | `Array` <Object> | |
| collisionData | `Pointer` <`Collision`> | |
| coopFlags | `integer` | read-only |
| ctx | `integer` | |
@ -2827,6 +2841,8 @@
| Field | Type | Access |
| ----- | ---- | ------ |
| norm | `Array` <`integer`> | |
| pos | `Array` <`integer`> | |
[:arrow_up_small:](#)
@ -3190,6 +3206,7 @@
| offsetY | `number` | |
| radius | `number` | |
| unused | `integer` | |
| walls | `Array` <Surface> | |
| x | `number` | |
| y | `number` | |
| z | `number` | |

View file

@ -741,12 +741,6 @@ NEXT_OPTION:
if (configDjuiTheme >= DJUI_THEME_MAX) { configDjuiTheme = 0; }
if (configDjuiScale >= 5) { configDjuiScale = 0; }
if (configExCoopTheme) {
configDjuiTheme = DJUI_THEME_LIGHT;
configDjuiThemeCenter = false;
configDjuiThemeFont = 1;
}
if (gCLIOpts.fullscreen == 1) {
configWindow.fullscreen = true;
} else if (gCLIOpts.fullscreen == 2) {

View file

@ -98,23 +98,19 @@ void djui_panel_main_menu_create(struct DjuiBase* caller) {
djui_themes_init();
{
struct DjuiCheckbox* center = djui_checkbox_create(body, DLANG(DJUI_THEMES, CENTER), &configDjuiThemeCenter, djui_panel_menu_options_djui_setting_change);
if (configExCoopTheme) { djui_base_set_enabled(&center->base, false); }
djui_checkbox_create(body, DLANG(DJUI_THEMES, CENTER), &configDjuiThemeCenter, djui_panel_menu_options_djui_setting_change);
char* themeChoices[DJUI_THEME_MAX];
for (int i = 0; i < DJUI_THEME_MAX; i++) {
themeChoices[i] = (char*)gDjuiThemes[i]->name;
}
struct DjuiSelectionbox* theme = djui_selectionbox_create(body, DLANG(DJUI_THEMES, DJUI_THEME), themeChoices, DJUI_THEME_MAX, &configDjuiTheme, djui_panel_menu_options_djui_setting_change);
if (configExCoopTheme) { djui_base_set_enabled(&theme->base, false); }
djui_selectionbox_create(body, DLANG(DJUI_THEMES, DJUI_THEME), themeChoices, DJUI_THEME_MAX, &configDjuiTheme, djui_panel_menu_options_djui_setting_change);
char* djuiScaleChoices[5] = {DLANG(DJUI_THEMES, AUTO), "x0.5", "x0.85", "x1.0", "x1.5"};
struct DjuiSelectionbox* scale = djui_selectionbox_create(body, DLANG(DJUI_THEMES, DJUI_SCALE), djuiScaleChoices, 5, &configDjuiScale, djui_panel_menu_options_djui_setting_change);
if (configExCoopTheme) { djui_base_set_enabled(&scale->base, false); }
djui_selectionbox_create(body, DLANG(DJUI_THEMES, DJUI_SCALE), djuiScaleChoices, 5, &configDjuiScale, djui_panel_menu_options_djui_setting_change);
char* djuiFontChoices[2] = {DLANG(DJUI_THEMES, FONT_NORMAL), DLANG(DJUI_THEMES, FONT_ALIASED)};
struct DjuiSelectionbox* font = djui_selectionbox_create(body, DLANG(DJUI_THEMES, DJUI_FONT), djuiFontChoices, 2, &configDjuiThemeFont, djui_panel_menu_options_djui_setting_change);
if (configExCoopTheme) { djui_base_set_enabled(&font->base, false); }
djui_selectionbox_create(body, DLANG(DJUI_THEMES, DJUI_FONT), djuiFontChoices, 2, &configDjuiThemeFont, djui_panel_menu_options_djui_setting_change);
if (gDjuiInMainMenu) {
// get level choices

View file

@ -327,6 +327,97 @@ struct LuaObjectField* smlua_get_custom_field(lua_State* L, u32 lot, int keyInde
// CObject get/set //
/////////////////////
static bool smlua_push_field(lua_State* L, u8* p, struct LuaObjectField *data) {
switch (data->valueType) {
case LVT_BOOL: lua_pushboolean(L, *(u8* )p); break;
case LVT_U8: lua_pushinteger(L, *(u8* )p); break;
case LVT_U16: lua_pushinteger(L, *(u16*)p); break;
case LVT_U32: lua_pushinteger(L, *(u32*)p); break;
case LVT_S8: lua_pushinteger(L, *(s8* )p); break;
case LVT_S16: lua_pushinteger(L, *(s16*)p); break;
case LVT_S32: lua_pushinteger(L, *(s32*)p); break;
case LVT_F32: lua_pushnumber( L, *(f32*)p); break;
case LVT_U64: lua_pushinteger(L, *(u64*)p); break;
case LVT_COBJECT: smlua_push_object(L, data->lot, p); break;
case LVT_COBJECT_P: smlua_push_object(L, data->lot, *(u8**)p); break;
case LVT_STRING: lua_pushstring(L, (char*)p); break;
case LVT_STRING_P: lua_pushstring(L, *(char**)p); break;
case LVT_BEHAVIORSCRIPT: lua_pushinteger(L, *(s32*)p); break;
case LVT_OBJECTANIMPOINTER: lua_pushinteger(L, *(s32*)p); break;
case LVT_COLLISION: lua_pushinteger(L, *(s32*)p); break;
case LVT_LEVELSCRIPT: lua_pushinteger(L, *(s32*)p); break;
case LVT_TRAJECTORY: lua_pushinteger(L, *(s16*)p); break;
// pointers
case LVT_BOOL_P:
case LVT_U8_P:
case LVT_U16_P:
case LVT_U32_P:
case LVT_S8_P:
case LVT_S16_P:
case LVT_S32_P:
case LVT_F32_P:
case LVT_U64_P:
case LVT_BEHAVIORSCRIPT_P:
case LVT_OBJECTANIMPOINTER_P:
case LVT_COLLISION_P:
case LVT_LEVELSCRIPT_P:
case LVT_TRAJECTORY_P:
smlua_push_pointer(L, data->valueType, *(u8**)p);
break;
default:
return true;
}
return false;
}
static bool smlua_set_field(lua_State* L, u8* p, struct LuaObjectField *data) {
void* valuePointer = NULL;
switch (data->valueType) {
case LVT_BOOL:*(u8*) p = smlua_to_boolean(L, 3); break;
case LVT_U8: *(u8*) p = smlua_to_integer(L, 3); break;
case LVT_U16: *(u16*)p = smlua_to_integer(L, 3); break;
case LVT_U32: *(u32*)p = smlua_to_integer(L, 3); break;
case LVT_S8: *(s8*) p = smlua_to_integer(L, 3); break;
case LVT_S16: *(s16*)p = smlua_to_integer(L, 3); break;
case LVT_S32: *(s32*)p = smlua_to_integer(L, 3); break;
case LVT_F32: *(f32*)p = smlua_to_number(L, 3); break;
case LVT_U64: *(s64*)p = smlua_to_integer(L, 3); break;
case LVT_COBJECT_P:
valuePointer = smlua_to_cobject(L, 3, data->lot);
if (gSmLuaConvertSuccess) {
*(u8**)p = valuePointer;
}
break;
// pointers
case LVT_BOOL_P:
case LVT_U8_P:
case LVT_U16_P:
case LVT_U32_P:
case LVT_S8_P:
case LVT_S16_P:
case LVT_S32_P:
case LVT_F32_P:
case LVT_U64_P:
case LVT_BEHAVIORSCRIPT_P:
case LVT_OBJECTANIMPOINTER_P:
case LVT_COLLISION_P:
case LVT_TRAJECTORY_P:
valuePointer = smlua_to_cpointer(L, 3, data->valueType);
if (gSmLuaConvertSuccess) {
*(u8**)p = valuePointer;
}
break;
default:
return true;
}
return false;
}
static int smlua__get_field(lua_State* L) {
LUA_STACK_CHECK_BEGIN_NUM(1);
@ -367,47 +458,21 @@ static int smlua__get_field(lua_State* L) {
}
u8* p = ((u8*)(intptr_t)pointer) + data->valueOffset;
switch (data->valueType) {
case LVT_BOOL: lua_pushboolean(L, *(u8* )p); break;
case LVT_U8: lua_pushinteger(L, *(u8* )p); break;
case LVT_U16: lua_pushinteger(L, *(u16*)p); break;
case LVT_U32: lua_pushinteger(L, *(u32*)p); break;
case LVT_S8: lua_pushinteger(L, *(s8* )p); break;
case LVT_S16: lua_pushinteger(L, *(s16*)p); break;
case LVT_S32: lua_pushinteger(L, *(s32*)p); break;
case LVT_F32: lua_pushnumber( L, *(f32*)p); break;
case LVT_U64: lua_pushinteger(L, *(u64*)p); break;
case LVT_COBJECT: smlua_push_object(L, data->lot, p); break;
case LVT_COBJECT_P: smlua_push_object(L, data->lot, *(u8**)p); break;
case LVT_STRING: lua_pushstring(L, (char*)p); break;
case LVT_STRING_P: lua_pushstring(L, *(char**)p); break;
case LVT_BEHAVIORSCRIPT: lua_pushinteger(L, *(s32*)p); break;
case LVT_OBJECTANIMPOINTER: lua_pushinteger(L, *(s32*)p); break;
case LVT_COLLISION: lua_pushinteger(L, *(s32*)p); break;
case LVT_LEVELSCRIPT: lua_pushinteger(L, *(s32*)p); break;
case LVT_TRAJECTORY: lua_pushinteger(L, *(s16*)p); break;
// pointers
case LVT_BOOL_P:
case LVT_U8_P:
case LVT_U16_P:
case LVT_U32_P:
case LVT_S8_P:
case LVT_S16_P:
case LVT_S32_P:
case LVT_F32_P:
case LVT_U64_P:
case LVT_BEHAVIORSCRIPT_P:
case LVT_OBJECTANIMPOINTER_P:
case LVT_COLLISION_P:
case LVT_LEVELSCRIPT_P:
case LVT_TRAJECTORY_P:
smlua_push_pointer(L, data->valueType, *(u8**)p);
break;
default:
if (data->count == 1) {
if (smlua_push_field(L, p, data)) {
LOG_LUA_LINE("_get_field on unimplemented type '%d', key '%s'", data->valueType, key);
return 0;
}
} else {
lua_newtable(L);
for (u16 i = 0; i < data->count; i++) {
lua_pushinteger(L, i + 1);
if (smlua_push_field(L, p + (i * data->size), data)) {
LOG_LUA_LINE("_get_field on unimplemented type '%d', key '%s'", data->valueType, key);
return 0;
}
lua_settable(L, -3);
}
}
LUA_STACK_CHECK_END();
@ -447,53 +512,30 @@ static int smlua__set_field(lua_State* L) {
return 0;
}
void* valuePointer = NULL;
u8* p = ((u8*)(intptr_t)pointer) + data->valueOffset;
switch (data->valueType) {
case LVT_BOOL:*(u8*) p = smlua_to_boolean(L, 3); break;
case LVT_U8: *(u8*) p = smlua_to_integer(L, 3); break;
case LVT_U16: *(u16*)p = smlua_to_integer(L, 3); break;
case LVT_U32: *(u32*)p = smlua_to_integer(L, 3); break;
case LVT_S8: *(s8*) p = smlua_to_integer(L, 3); break;
case LVT_S16: *(s16*)p = smlua_to_integer(L, 3); break;
case LVT_S32: *(s32*)p = smlua_to_integer(L, 3); break;
case LVT_F32: *(f32*)p = smlua_to_number(L, 3); break;
case LVT_U64: *(s64*)p = smlua_to_integer(L, 3); break;
case LVT_COBJECT_P:
valuePointer = smlua_to_cobject(L, 3, data->lot);
if (gSmLuaConvertSuccess) {
*(u8**)p = valuePointer;
}
break;
// pointers
case LVT_BOOL_P:
case LVT_U8_P:
case LVT_U16_P:
case LVT_U32_P:
case LVT_S8_P:
case LVT_S16_P:
case LVT_S32_P:
case LVT_F32_P:
case LVT_U64_P:
case LVT_BEHAVIORSCRIPT_P:
case LVT_OBJECTANIMPOINTER_P:
case LVT_COLLISION_P:
case LVT_TRAJECTORY_P:
valuePointer = smlua_to_cpointer(L, 3, data->valueType);
if (gSmLuaConvertSuccess) {
*(u8**)p = valuePointer;
}
break;
default:
if (data->count == 1) {
if (smlua_set_field(L, p, data)) {
LOG_LUA_LINE("_set_field on unimplemented type '%d', key '%s'", data->valueType, key);
return 0;
}
if (!gSmLuaConvertSuccess) {
LOG_LUA_LINE("_set_field failed to retrieve value type '%d', key '%s'", data->valueType, key);
return 0;
}
if (!gSmLuaConvertSuccess) {
LOG_LUA_LINE("_set_field failed to retrieve value type '%d', key '%s'", data->valueType, key);
return 0;
}
} else {
lua_newtable(L);
for (u16 i = 0; i < data->count; i++) {
lua_pushinteger(L, i + 1);
if (smlua_set_field(L, p + (i * data->size), data)) {
LOG_LUA_LINE("_set_field on unimplemented type '%d', key '%s'", data->valueType, key);
return 0;
}
if (!gSmLuaConvertSuccess) {
LOG_LUA_LINE("_set_field failed to retrieve value type '%d', key '%s'", data->valueType, key);
return 0;
}
lua_settable(L, -3);
}
}
LUA_STACK_CHECK_END();

View file

@ -45,6 +45,8 @@ struct LuaObjectField {
size_t valueOffset;
bool immutable;
u16 lot;
u16 count;
u32 size;
};
struct LuaObjectTable {

File diff suppressed because it is too large Load diff

View file

@ -292,6 +292,7 @@ char gSmluaConstants[] = ""
"WARP_TRANSITION_FADE_INTO_MARIO = 0x11\n"
"WARP_TRANSITION_FADE_FROM_BOWSER = 0x12\n"
"WARP_TRANSITION_FADE_INTO_BOWSER = 0x13\n"
"VERSION_REGION = 'US'\n"
"id_bhv1Up = 0\n"
"id_bhv1upJumpOnApproach = 1\n"
"id_bhv1upRunningAway = 2\n"
@ -4323,9 +4324,5 @@ char gSmluaConstants[] = ""
"VERSION_TEXT = 'v'\n"
"VERSION_NUMBER = 38\n"
"MINOR_VERSION_NUMBER = 1\n"
"VERSION_REGION = 'JP'\n"
"VERSION_REGION = 'EU'\n"
"VERSION_REGION = 'SH'\n"
"VERSION_REGION = 'US'\n"
"MAX_VERSION_LENGTH = 32\n"
;