Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
4 registered members (TipmyPip, AndrewAMD, dBc, clonman), 18,621 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
how to pass function as parameter #431614
10/20/13 16:40
10/20/13 16:40
Joined: Apr 2006
Posts: 159
Latvija
Arrovs Offline OP
Member
Arrovs  Offline OP
Member

Joined: Apr 2006
Posts: 159
Latvija
i want to put function as parameter for function, but how you can do it?

tried like this:
function take_function(function parameter(void*))

and also tried like in C, but without success.


Arrovs once will publish game
Re: how to pass function as parameter [Re: Arrovs] #431615
10/20/13 17:00
10/20/13 17:00
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
Here you go
Code:
function take_function(void *fnPtr)
{
    function parameter(void* arg);
    parameter = fnPtr;
}



Visit my site: www.masterq32.de
Re: how to pass function as parameter [Re: Arrovs] #431616
10/20/13 17:08
10/20/13 17:08
Joined: Sep 2009
Posts: 1,032
Budapest
Aku_Aku Offline
Serious User
Aku_Aku  Offline
Serious User

Joined: Sep 2009
Posts: 1,032
Budapest
Originally Posted By: Gamestudio Manual
Function pointers
Pointers of functions or actions can be defined as FUNCTION* under C-Script. LC Under lite-C a function pointer is defined just as a function prototype with return and parameter types. Example:
Code:
float myfunction(int a, float b); // define a function pointer named "myfunction"  

float fTest(int a, float b) { return (a*b); }
...
myfunction = fTest;
x = myfunction(y,z);


For storing arrays of function pointers in lite-C, void* arrays can be used. Example:
Code:
float myfunction(int a, float b); // define a function pointer

void* function_array[100];        // define a pointer array

float fTest(int a, float b) { return (a*b); }
...
function_array[n] = fTest;
myfunction = function_array[n];
x = myfunction(y,z);



Last edited by Aku_Aku; 10/20/13 17:09.
Re: how to pass function as parameter [Re: Aku_Aku] #431618
10/20/13 18:12
10/20/13 18:12
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
Without parameters:
Code:
function execute_me()
{
	error("lol");
}

function get_param_and_execute(void *pFunc)
{
	function typedef_func();
	typedef_func = pFunc;
	typedef_func();
}

...

get_param_and_execute(execute_me);



With parameters:
Code:
function execute_me(STRING *strMsg)
{
	error(strMsg);
}

function get_param_and_execute(void *pFunc, STRING *strMsg)
{
	function typedef_func(STRING*);
	typedef_func = pFunc;
	typedef_func(strMsg);
}

...

get_param_and_execute(execute_me, "works!");


Re: how to pass function as parameter [Re: Ch40zzC0d3r] #431646
10/21/13 16:29
10/21/13 16:29
Joined: Apr 2006
Posts: 159
Latvija
Arrovs Offline OP
Member
Arrovs  Offline OP
Member

Joined: Apr 2006
Posts: 159
Latvija
thanks.


Arrovs once will publish game

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | 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