CallFunctionFast in Thread from LUA FFI

Just starting out? Need help? Post your questions and find answers here.
beo6
User
User
Posts: 17
Joined: Thu Mar 18, 2010 11:28 pm

CallFunctionFast in Thread from LUA FFI

Post 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.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: CallFunctionFast in Thread from LUA FFI

Post 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).
BERESHEIT
beo6
User
User
Posts: 17
Joined: Thu Mar 18, 2010 11:28 pm

Re: CallFunctionFast in Thread from LUA FFI

Post 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?)
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: CallFunctionFast in Thread from LUA FFI

Post by Danilo »

Did you try "ProcedureCDLL CallBackTest()"? Maybe LUA uses C calling convention when calling PB functions.
Post Reply