mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2026-05-10 10:51:39 +00:00
* CObject Properties
- Added property members to CObjects via `PROPERTY` macro
`PROPERTY(name, get, set)`
- `name`: property name
- `get`: `fun(self): value`
- `set`: `fun(self, value)`
- Prettified `LuaObjectField` struct with unions for function/property value types
- Added properties to `struct ModAudio`
- `position`
- `looping`
- `frequency`
- `volume`
- NOTE: only work with streams- the audio reform will come later
* Define array size only when necessary
- new `__pairs` metamethod for `CObject`s, cycles through all of an object's fields, in alphabetical order
- stray semicolon!
84 lines
No EOL
2.1 KiB
Python
84 lines
No EOL
2.1 KiB
Python
import os
|
|
import re
|
|
import sys
|
|
from common import cobject_function_identifier, cobject_property_identifier
|
|
|
|
def extract_structs(filename):
|
|
with open(filename) as file:
|
|
lines = file.readlines()
|
|
|
|
txt = ''
|
|
# strip line continuation
|
|
for line in lines:
|
|
if line.strip().endswith('\\'):
|
|
txt += line.strip()[:-1] + ' '
|
|
else:
|
|
txt += line
|
|
|
|
# strip directives and comments
|
|
tmp = txt
|
|
txt = ''
|
|
for line in tmp.splitlines():
|
|
if line.strip().startswith('#'):
|
|
continue
|
|
if '//' in line:
|
|
line = line.split('//', 1)[0]
|
|
txt += line + '\n'
|
|
|
|
while ('/*' in txt):
|
|
s1 = txt.split('/*', 1)
|
|
s2 = s1[1].split('*/', 1)
|
|
txt = s1[0] + s2[-1]
|
|
|
|
# normalize newlines
|
|
txt = txt.replace('\n', ' ')
|
|
txt = txt.replace(';', ';\n')
|
|
txt = txt.replace('{', '{\n')
|
|
while (' ' in txt):
|
|
txt = txt.replace(' ', ' ')
|
|
|
|
# handle function members (NOT function pointers)
|
|
txt = re.sub(f'{cobject_function_identifier}\\((.*),(.*)\\)', f'{cobject_function_identifier} \\1\\2', txt)
|
|
|
|
# handle property members
|
|
txt = re.sub(f'{cobject_property_identifier}\\((.*),(.*),(.*)\\)', f'{cobject_property_identifier} \\1\\2\\3', txt)
|
|
|
|
# strip macros
|
|
txt = re.sub(r'[^a-zA-Z0-9_][A-Z0-9_]+\(.*\)', '', txt)
|
|
|
|
# strip blocks
|
|
tmp = txt
|
|
txt = ''
|
|
inside = 0
|
|
for character in tmp:
|
|
if character == '\n':
|
|
if inside == 0:
|
|
txt += character
|
|
else:
|
|
txt += character
|
|
|
|
if character == '{':
|
|
inside += 1
|
|
|
|
if character == '}':
|
|
inside -= 1
|
|
|
|
# extract structs
|
|
tmp = txt
|
|
txt = ''
|
|
for line in tmp.splitlines():
|
|
line = line.strip()
|
|
if '{' not in line:
|
|
continue
|
|
if '}' not in line:
|
|
continue
|
|
if ';' not in line:
|
|
continue
|
|
if not line.startswith('struct ') and not line.startswith('typedef struct '):
|
|
continue
|
|
txt += line + '\n'
|
|
|
|
return txt.splitlines()
|
|
|
|
if __name__ == "__main__":
|
|
print(extract_structs(sys.argv[1])) |