Page 1 of 1

CallFunctionFast in Thread from LUA FFI

Posted: Mon Apr 13, 2015 1:48 am
by beo6
Hello everyone,

i got a small issue.

I am including a DLL compiled with Purebasic into LUA using FFI.
(Threadsafe is enabled in the compile settings)

Now there is the possibility of using CallBacks in giving a LUA Function to a Purebasic Procedure.

So far that works very nice. Except when i start a Thread in the Purebasic DLL it crashes.
I think i tried everything now but it just doesn´t work.

Example:

Code: Select all

Procedure TestThread(*function)
  CallFunctionFast(*function)
EndProcedure
ProcedureDLL CallBackTest(*function)
  CreateThread(@TestThread(), *function)
EndProcedure
i also tried using CallCFunctionFast with same result. outside of the Thread it works, but calling from a thread it crashes.
Maybe it is really a problem with LUA?
I am also not sure how i should debug it correctly. I hope someone can help me here.

Thanks in advance.

Re: CallFunctionFast in Thread from LUA FFI

Posted: Mon Apr 13, 2015 1:56 am
by netmaestro
A much more robust and solid alternative to CallFunctionFast is the prototype. You might try switching to that and of course make sure your threadsafe switch is on (but I assume you didn't need that tip).

Re: CallFunctionFast in Thread from LUA FFI

Posted: Mon Apr 13, 2015 11:29 am
by beo6
Thank you.

I tested it using Prototype and PrototypeC but it still crashes.

Code: Select all

PrototypeC GetStatus()

Declare TestThread(*param)
ProcedureDLL CallBackTest(*function)
  Global ProtoTest.GetStatus = *function
  CreateThread(@TestThread(), 0)
EndProcedure
Procedure TestThread(*param)
  
  ProtoTest()
EndProcedure
I have the feeling that Callbacks from a Thread to Lua FFI are not supported. (Probably a LUA issue?)

Re: CallFunctionFast in Thread from LUA FFI

Posted: Mon Apr 13, 2015 6:53 pm
by Danilo
Did you try "ProcedureCDLL CallBackTest()"? Maybe LUA uses C calling convention when calling PB functions.