Gamestudio Links
Zorro Links
Newest Posts
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
3 registered members (AndrewAMD, degenerate_762, ozgur), 1,311 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 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: 993
Budapest
Aku_Aku Offline
User
Aku_Aku  Offline
User

Joined: Sep 2009
Posts: 993
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 | 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