Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 01:28
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (7th_zorro), 793 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
user data for callbacks #224023
08/28/08 01:22
08/28/08 01:22
Joined: Feb 2007
Posts: 353
A
amy Offline OP
Senior Member
amy  Offline OP
Senior Member
A

Joined: Feb 2007
Posts: 353
Writing wrappers for other programming languages would be easier if user data could be specified for callbacks the engine uses. Just like the Newton engine handles this. Without support for user data itīs often necessary to do ugly workarounds.

Re: user data for callbacks [Re: amy] #224060
08/28/08 10:07
08/28/08 10:07
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
User data for callbacks - do you mean function parameters? You can use callback functions with as many parameters as you want.

Re: user data for callbacks [Re: jcl] #224086
08/28/08 12:40
08/28/08 12:40
Joined: Feb 2007
Posts: 353
A
amy Offline OP
Senior Member
amy  Offline OP
Senior Member
A

Joined: Feb 2007
Posts: 353
How can I use callbacks with as many parameters as I want?

I mean something like this for example (pseudocode):

Code:
void c_callback(userdata)
{
  call_python_function(userdata, my);
}

[...]
my.event = c_callback; // always the same function for the wrapper
my.eventuserdata = python_callback;


Hm... Well, I could use a skill in this case but thatīs not very elegant and I would have to warn every user of the wrapper with "NEVER USE SKILL100 YOURSELF!" or something. smile

Re: user data for callbacks [Re: amy] #224247
08/29/08 10:05
08/29/08 10:05
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Hmm, I know that I'm very stupid, but why are you assigning a callback function to an event, and what is your "eventuserdata" supposed to mean?

Callback functions are usually passed to a library in function arguments. They are stored in a function pointer and then called like any other function.

Re: user data for callbacks [Re: jcl] #224281
08/29/08 13:07
08/29/08 13:07
Joined: Feb 2007
Posts: 353
A
amy Offline OP
Senior Member
amy  Offline OP
Senior Member
A

Joined: Feb 2007
Posts: 353
Maybe I use the wrong terminology but isnīt this a callback? I tell the engine which function to call when a collision happens. I donīt pass the callback to a library in function arguments like you wrote but assign the function pointer to my.event.

Since C can only call C functions I have to do something like above if I want to expose the callback functionality to another language like Python. I want to write a Python wrapper and I want achieve that collision callbacks can also be written in Python.

Re: user data for callbacks [Re: amy] #224284
08/29/08 13:24
08/29/08 13:24
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Ah, ok. Your "c_callback" is not a callback, it's an event function. You can pass any parameters to callback functions, but the parameters for event functions are specified and depend on the kind of event.

You event function can just collect the required data from the 'my' entity and then call the python function.


Moderated by  aztec, Spirit 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1