Gamestudio Links
Zorro Links
Newest Posts
Lapsa's very own thread
by Lapsa. 06/26/24 12:45
Executing Trades on Next Bar Open
by Zheka. 06/20/24 14:26
A simple game ...
by VoroneTZ. 06/18/24 10:50
Face player all the time ...
by bbn1982. 06/18/24 10:25
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (henrybane, 1 invisible), 775 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mino, squik, AemStones, LucasJoshua, Baklazhan
19061 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
is possible lite-C`struct contain any functions #340320
09/03/10 08:31
09/03/10 08:31
Joined: Dec 2009
Posts: 128
China
frankjiang Offline OP
Member
frankjiang  Offline OP
Member

Joined: Dec 2009
Posts: 128
China
is possible lite-C`struct contain any functions
---------------------------------------------------------------
void func(){
printf("hello world");
}
typedef struct{
var x;
var y;
int (*func)(int,int);
}SPOT;
---------------------------------------------------------------


development 3d game is interesting!
Re: is possible lite-C`struct contain any functions [Re: frankjiang] #340322
09/03/10 08:39
09/03/10 08:39
Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Tobias Offline

Moderator
Tobias  Offline

Moderator

Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Yes, but with different syntax, the normal lite-C structs use the EVENT type for function pointers. You can see examples in atypes.h. I believe EVENT is typedef void* but I'm not sure.

Re: is possible lite-C`struct contain any functions [Re: Tobias] #340324
09/03/10 08:43
09/03/10 08:43
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
This should work:
Code:
void func()
{
	printf("hello world");
}


typedef struct
{
	var x;
	var y;
	int func();
} SPOT;

// ...
SPOT spot;
spot.func = func;

//...
spot.func();




Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: is possible lite-C`struct contain any functions [Re: WretchedSid] #340325
09/03/10 09:08
09/03/10 09:08
Joined: Dec 2009
Posts: 128
China
frankjiang Offline OP
Member
frankjiang  Offline OP
Member

Joined: Dec 2009
Posts: 128
China
Error in 'MAIN' line 21: Call function @temp_00093 error< spot.func();>


development 3d game is interesting!
Re: is possible lite-C`struct contain any functions [Re: frankjiang] #340329
09/03/10 09:34
09/03/10 09:34
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
you need to do it like this:Adjust the font size
Make textarea smaller
Make textarea bigger
Code:
typedef struct
{
    var x;
    var y;
    void fn(var x);    //The function pointer
} SPOT;
void func(var x)    //your function
{
    error("Hello world!");
}

SPOT* setup_spot()  //a init routine
{
    SPOT* spot = sys_malloc(sizeof(SPOT));
    spot->x = 0;
    spot->y = 0;
    spot->fn = func;  //Set fn as func
    return spot;
}

void main()
{
    SPOT* spot = setup_spot();  //create SPOT
    spot->fn(5);   //call func();
}



EDIT: Sorry, old code won't work!
don't know why code doesn't work without parameters...
with params it works

Last edited by Richi007; 09/03/10 09:43.

Visit my site: www.masterq32.de
Re: is possible lite-C`struct contain any functions [Re: MasterQ32] #340330
09/03/10 09:40
09/03/10 09:40
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
I'm doing it slightly different.

I store a string in my struct, and use engine_getfunction together with a prototype function to call custom functions.

If you dont know what I mean, i can give an example when i'm back home.

regards,


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
Re: is possible lite-C`struct contain any functions [Re: MasterQ32] #340331
09/03/10 09:43
09/03/10 09:43
Joined: Dec 2009
Posts: 128
China
frankjiang Offline OP
Member
frankjiang  Offline OP
Member

Joined: Dec 2009
Posts: 128
China
Error in 'MAIN' line 21: '@temp_00716': wrong number/type of parameters<spot->fn(); //call func();>


development 3d game is interesting!
Re: is possible lite-C`struct contain any functions [Re: frankjiang] #340332
09/03/10 09:44
09/03/10 09:44
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
changed post!
Code:
typedef struct
{
    var x;
    var y;
    void fn(var x);    //The function pointer
} SPOT;
void func(var x)    //your function
{
    error("Hello world!");
}

SPOT* setup_spot()  //a init routine
{
    SPOT* spot = sys_malloc(sizeof(SPOT));
    spot->x = 0;
    spot->y = 0;
    spot->fn = func;  //Set fn as func
    return spot;
}

void main()
{
    SPOT* spot = setup_spot();  //create SPOT
    spot->fn(5);   //call func();
}



don't know why code doesn't work without parameters...
with params it works


Visit my site: www.masterq32.de
Re: is possible lite-C`struct contain any functions [Re: MasterQ32] #340333
09/03/10 09:45
09/03/10 09:45
Joined: Dec 2009
Posts: 128
China
frankjiang Offline OP
Member
frankjiang  Offline OP
Member

Joined: Dec 2009
Posts: 128
China
Error in 'MAIN' line 21:
'@temp_00716': wrong number/type of parameters
< spot->fn(); //call func();
>


development 3d game is interesting!
Re: is possible lite-C`struct contain any functions [Re: frankjiang] #340336
09/03/10 10:02
09/03/10 10:02
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
Code:
typedef struct
{
    var x;
    var y;
    STRING *funcName;    //The function pointer
} SPOT;

void callingFunction()    //your function
{
    error("Hello world!");
}

SPOT* setup_spot()  //a init routine
{
    SPOT* spot = sys_malloc(sizeof(SPOT));
    
    spot->x = 0;
    spot->y = 0;
    spot->funcName = str_create("");  //Set fn as func
    str_cpy(spot->funcName, "callingFunction");
    
    return(spot);
}

// empty prototype function
void PrototypeCallFunction();

void main()
{
    SPOT* spot = setup_spot();  //create SPOT
    
    PrototypeCallFunction = engine_getscript(_chr(spot->funcName));
    if(PrototypeCallFunction) { PrototypeCallFunction(); }
}



Tested, and works.

regards,


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
Page 1 of 3 1 2 3

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