From 6b1a47cf1a356a1c54d715aaa34cfb4ca224763d Mon Sep 17 00:00:00 2001 From: sebaszm Date: Fri, 22 Nov 2024 14:05:30 +0100 Subject: [PATCH] [LuaGenerator] Add support for Optional and fixed arrays --- LuaGenerator/GenerateLua.sh | 4 ++-- ProxyStubGenerator/StubGenerator.py | 29 +++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/LuaGenerator/GenerateLua.sh b/LuaGenerator/GenerateLua.sh index 5f80694..a976741 100755 --- a/LuaGenerator/GenerateLua.sh +++ b/LuaGenerator/GenerateLua.sh @@ -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." diff --git a/ProxyStubGenerator/StubGenerator.py b/ProxyStubGenerator/StubGenerator.py index 1aece6b..356ec0f 100755 --- a/ProxyStubGenerator/StubGenerator.py +++ b/ProxyStubGenerator/StubGenerator.py @@ -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": @@ -303,6 +303,7 @@ def _Convert(size): size = "8" + value = 0 expr = "".join(length) try: value = eval(expr) @@ -313,7 +314,7 @@ def _Convert(size): except: pass - return [size, None] + return [size, value] def Convert(paramtype, retval, vars, hresult=False): @@ -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: @@ -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 @@ -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) @@ -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]