Skip to content

Commit

Permalink
Try converting all lua values sent to python function to the python e…
Browse files Browse the repository at this point in the history
…quivalent since we are swapping threads. Lua does not like accessing the types from another thread
  • Loading branch information
mickeprag committed Apr 13, 2017
1 parent 5dda7b5 commit 202a590
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lua/src/lua/LuaScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,10 @@ def proxyMethod(*args, **kwargs):
args = list(args)
if len(args) >= 2 and lua_type(args[1]) == 'table':
# First parameter is a lua table. Handle this as **kwargs call
kwargs = dict(args[1])
kwargs = self.__wrapArgument(args[1])
del args[1]
# TODO: Also loop through kwargs and look for lua types
for i, arg in enumerate(args):
if lua_type(arg) == 'function':
t = LuaFunctionWrapper(self, arg)
args[i] = t
self.references.append(weakref.ref(t))
args[i] = self.__wrapArgument(args[i])
try:
Application().queue(mainThreadCaller, args, kwargs)
condition.wait(20) # Timeout to not let the script hang forever
Expand All @@ -405,3 +401,16 @@ def proxyMethod(*args, **kwargs):
def __setter(self, obj, attrName, value):
# Set it in the main thread
Application().queue(setattr, obj, attrName, value)

def __wrapArgument(self, arg):
if lua_type(arg) == 'function':
t = LuaFunctionWrapper(self, arg)
self.references.append(weakref.ref(t))
return t
elif lua_type(arg) == 'table':
table = dict(arg)
for key in table:
# Recursive wrap
table[key] = self.__wrapArgument(table[key])
return table
return arg

0 comments on commit 202a590

Please sign in to comment.