Skip to content

Commit

Permalink
[LuaGenerator] Add support for Optional and fixed arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
sebaszm committed Nov 22, 2024
1 parent f246e36 commit 6b1a47c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
4 changes: 2 additions & 2 deletions LuaGenerator/GenerateLua.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ THUNDER_DIR="${1:-../../Thunder}"
INTERFACES_DIR="${2:-../../ThunderInterfaces}"

files="$THUNDER_DIR/Source/com/ICOM.h"
files="$files $THUNDER_DIR/Source/plugins/IController.h $THUNDER_DIR/Source/plugins/IControllerDeprecated.h $THUNDER_DIR/Source/plugins/IPlugin.h $THUNDER_DIR/Source/plugins/IShell.h $THUNDER_DIR/Source/plugins/IStateControl.h $THUNDER_DIR/Source/plugins/ISubSystem.h $THUNDER_DIR/Source/plugins/IDispatcher.h"
files="$files $THUNDER_DIR/Source/plugins/IController.h $ $THUNDER_DIR/Source/plugins/IPlugin.h $THUNDER_DIR/Source/plugins/IShell.h $THUNDER_DIR/Source/plugins/IStateControl.h $THUNDER_DIR/Source/plugins/ISubSystem.h $THUNDER_DIR/Source/plugins/IDispatcher.h"
files="$files $INTERFACES_DIR/interfaces/I*.h"
# add more interface files if needed..

echo "Generating lua data file..."

../ProxyStubGenerator/StubGenerator.py --lua-code $files --outdir . -I $THUNDER_DIR/Source -i $THUNDER_DIR/Source/com/Ids.h
../ProxyStubGenerator/StubGenerator.py --lua-code $files --outdir . -I $THUNDER_DIR/Source -i $THUNDER_DIR/Source/com/Ids.h --verbose

echo "Complete."
29 changes: 23 additions & 6 deletions ProxyStubGenerator/StubGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def _Convert(size):
else:
return "16"

if len(length) == 1:
if isinstance(length, list) and len(length) == 1:
if length[0] == "void":
return [_Convert(param.Type().size), None]
elif length[0] == "return":
Expand All @@ -303,6 +303,7 @@ def _Convert(size):

size = "8"

value = 0
expr = "".join(length)
try:
value = eval(expr)
Expand All @@ -313,7 +314,7 @@ def _Convert(size):
except:
pass

return [size, None]
return [size, value]


def Convert(paramtype, retval, vars, hresult=False):
Expand All @@ -324,14 +325,24 @@ def Convert(paramtype, retval, vars, hresult=False):
meta = paramtype.meta
p = param.Type()

if isinstance(p, CppParser.Optional):
optional_type = Convert(p.optional, retval, vars, hresult)
optional_type.append("optional = true")
print(optional_type)
return optional_type

if isinstance(p, CppParser.Integer):
length_param = None
length_value = None

if param.IsPointer():
parsed = ParseLength(param, meta.length if meta.length else meta.maxlength, retval, vars)
parsed = ParseLength(param, paramtype.array if paramtype.array else meta.length if meta.length else meta.maxlength, retval, vars)

if parsed[1]:
length_param = parsed[1]
if (isinstance(parsed[1], str)):
length_param = parsed[1]
elif (isinstance(parsed[1], int)):
length_value = parsed[1]

value = "BUFFER" + parsed[0]
else:
Expand Down Expand Up @@ -368,6 +379,8 @@ def Convert(paramtype, retval, vars, hresult=False):

if length_param:
rvalue.append("length_param = \"%s\"" % length_param)
elif length_value:
rvalue.append("length_value = %i" % length_value)

return rvalue

Expand Down Expand Up @@ -395,7 +408,7 @@ def Convert(paramtype, retval, vars, hresult=False):
for v in kind.vars:
param_info = Convert(v, None, kind.vars)
text = []
text.append("name = " + v.name)
text.append('name = "%s"' % v.name)

if param_info:
text.extend(param_info)
Expand Down Expand Up @@ -424,7 +437,11 @@ def Convert(paramtype, retval, vars, hresult=False):
if name not in enums_list:
data = dict()
for e in p.items:
data[e.value] = e.name
if (isinstance(e.value, int)):
data[e.value] = e.name
else:
log.Warn("unable to evaluate enum value '%s'" % "".join([str(x) for x in e.value]))

enums_list[name] = data

value = ["type = Type.ENUM" + signed + value, "enum = \"%s\"" % name]
Expand Down

0 comments on commit 6b1a47c

Please sign in to comment.