Update Lua documentation autogeneration

This commit is contained in:
MysterD 2022-03-04 22:22:31 -08:00
parent e740529776
commit e4f72105a3
6 changed files with 2429 additions and 2425 deletions

View file

@ -115,38 +115,42 @@ def translate_type_to_lot(ptype):
def translate_type_to_lua(ptype): def translate_type_to_lua(ptype):
if ptype.startswith('struct '): if ptype.startswith('struct '):
return ptype.split(' ')[1].replace('*', ''), True ptype = ptype.split(' ')[1].replace('*', '')
return ptype, 'structs.md#%s' % ptype
if ptype == 'const char*': if ptype == 'const char*':
return 'string', False return '`string`', None
if ptype == 'char*' or ('char' in ptype and '[' in ptype): if ptype == 'char*' or ('char' in ptype and '[' in ptype):
return 'string', False return '`string`', None
if 'Vec3' in ptype: if 'Vec3' in ptype:
return ptype, True return ptype, 'structs.md#%s' % ptype
if ptype.startswith('enum '): if ptype.startswith('enum '):
return 'integer', False return ptype, 'constants.md#%s' % ptype.replace(' ', '-')
if ptype in usf_types: if ptype in usf_types:
if ptype.startswith('f'): if ptype.startswith('f'):
return 'number', False return '`number`', None
else: else:
return 'integer', False return '`integer`', None
if 'void' == ptype: if 'void' == ptype:
return None, False return None, None
if ptype == 'LuaFunction': if ptype == 'LuaFunction':
return 'LuaFunction()', False return '`Lua Function` ()', None
if ptype.count('*') == 1 and '???' not in translate_type_to_lvt(ptype): if ptype.count('*') == 1 and '???' not in translate_type_to_lvt(ptype):
ptype = ptype.replace('const', '').replace('*', '').strip() ptype = ptype.replace('const', '').replace('*', '').strip()
s = 'Pointer <%s>' % translate_type_to_lua(ptype)[0] s = '`Pointer` <%s>' % translate_type_to_lua(ptype)[0]
return s, False return s, None
return ptype, False if not ptype.startswith('`'):
ptype = '`' + ptype + '`'
return ptype, None
def gen_comment_header(f): def gen_comment_header(f):
comment_h = "// " + f + " //" comment_h = "// " + f + " //"

View file

@ -432,7 +432,7 @@ def doc_lua_func_param(param):
lfp_type, lfp_link = translate_type_to_lua(lfp_type) lfp_type, lfp_link = translate_type_to_lua(lfp_type)
if lfp_link: if lfp_link:
s += '[%s](structs.md#%s)' % (lfp_type, lfp_type) s += '[%s](%s)' % (lfp_type, lfp_link)
else: else:
s += lfp_type s += lfp_type
@ -469,7 +469,7 @@ def doc_function(function):
ptype = doc_lua_func_param(param) ptype = doc_lua_func_param(param)
if plink: if plink:
s += '| %s | [%s](structs.md#%s) |\n' % (pid, ptype, ptype) s += '| %s | [%s](%s) |\n' % (pid, ptype, plink)
continue continue
s += '| %s | %s |\n' % (pid, ptype) s += '| %s | %s |\n' % (pid, ptype)
@ -480,7 +480,7 @@ def doc_function(function):
s += '\n### Returns\n' s += '\n### Returns\n'
if rtype != None: if rtype != None:
if rlink: if rlink:
s += '[%s](structs.md#%s)\n' % (rtype, rtype) s += '[%s](%s)\n' % (rtype, rlink)
else: else:
s += '- %s\n' % rtype s += '- %s\n' % rtype
else: else:

View file

@ -315,15 +315,15 @@ def doc_struct_field(struct, field):
if '???' in lvt or '???' in lot: if '???' in lvt or '???' in lot:
return '' return ''
ftype, do_link = translate_type_to_lua(ftype) ftype, flink = translate_type_to_lua(ftype)
restrictions = ('', 'read-only')[fimmutable == 'true'] restrictions = ('', 'read-only')[fimmutable == 'true']
global total_fields global total_fields
total_fields += 1 total_fields += 1
if do_link: if flink:
return '| %s | [%s](#%s) | %s |\n' % (fid, ftype, ftype, restrictions) return '| %s | [%s](%s) | %s |\n' % (fid, ftype, flink, restrictions)
return '| %s | %s | %s |\n' % (fid, ftype, restrictions) return '| %s | %s | %s |\n' % (fid, ftype, restrictions)

File diff suppressed because it is too large Load diff

View file

@ -21,8 +21,8 @@ Hooks are a way for SM64 to trigger Lua code, whereas the functions listed in [f
| ----- | ---- | ----- | | ----- | ---- | ----- |
| behaviorId | [enum BehaviorId](constants.md#enum-BehaviorId) | Set to `0` to create a new behavior | | behaviorId | [enum BehaviorId](constants.md#enum-BehaviorId) | Set to `0` to create a new behavior |
| objectList | [enum ObjectList](constants.md#enum-ObjectList) | | | objectList | [enum ObjectList](constants.md#enum-ObjectList) | |
| initFunction([Object](structs.md#Object) obj) | Lua Function | Runs once per object | | initFunction | `Lua Function` ([Object](structs.md#Object) obj) | Runs once per object |
| loopFunction([Object](structs.md#Object) obj) | Lua Function | Runs once per frame per object | | loopFunction | `Lua Function` ([Object](structs.md#Object) obj) | Runs once per frame per object |
### Returns ### Returns
- [enum BehaviorId](constants.md#enum-BehaviorId) - [enum BehaviorId](constants.md#enum-BehaviorId)
@ -53,9 +53,9 @@ id_bhvExample = hook_behavior(0, OBJ_LIST_DEFAULT, bhv_example_init, bhv_example
| Field | Type | | Field | Type |
| ----- | ---- | | ----- | ---- |
| command | string | | command | `string` |
| description | string | | description | `string` |
| func(`string` message) -> `bool` | Lua Function | | func | `Lua Function` (`string` message) -> `bool` |
### Lua Example ### Lua Example
@ -101,7 +101,7 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh
| Field | Type | | Field | Type |
| ----- | ---- | | ----- | ---- |
| hook_event_type | [HookEventType](#Hook-Event-Types) | | hook_event_type | [HookEventType](#Hook-Event-Types) |
| func(`...`) | Lua Function | | func | `Lua Function` (`...`) |
### Lua Example ### Lua Example
@ -125,8 +125,8 @@ hook_event(HOOK_MARIO_UPDATE, mario_update)
| Field | Type | | Field | Type |
| ----- | ---- | | ----- | ---- |
| action_id | integer | | action_id | `integer` |
| func([MarioState](structs.md#MarioState) m) | Lua Function | | func | `Lua Function` ([MarioState](structs.md#MarioState) m) |
| interaction_type | [enum InteractionFlag](constants.md#enum-InteractionFlag) <optional> | | interaction_type | [enum InteractionFlag](constants.md#enum-InteractionFlag) <optional> |
### Lua Example ### Lua Example
@ -204,10 +204,10 @@ hook_mario_action(ACT_WALL_SLIDE, act_wall_slide)
| Field | Type | | Field | Type |
| ----- | ---- | | ----- | ---- |
| syncTable | SyncTable | | syncTable | `SyncTable` |
| field | value | | field | `value` |
| tag | value | | tag | `value` |
| func(`value` tag, `value` oldValue, `value` newValue) | Lua Function | | func | `Lua Function` (`value` tag, `value` oldValue, `value` newValue) |
### Lua Example ### Lua Example

File diff suppressed because it is too large Load diff