Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
basik85278
by basik85278. 04/28/24 08:56
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (blaurock), 750 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Research: How to do classes in Lite-C #420043
03/18/13 23:38
03/18/13 23:38
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline OP
Expert
MasterQ32  Offline OP
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
Hey!

I was just playing around with Lite-C when i remembered that Lite-C supports C++ API with Classes (like DirectX9).
The syntax was pretty easy and i made some tests.
My results: You can have classes in Lite-C nativly, but with a different setup as in C++.

So how do i create a class?
Just check this code example:
Code:
#include <acknex.h>

typedef struct ITestVtbl
{	
	int answer;
	void sayHello(void *This);
} ITestVtbl;

typedef interface ITest
{
	ITestVtbl *lpVtbl;
} ITest;

void ITest_sayHello(ITest *This)
{
	printf("Answer to live: %d", This->answer);
}

ITest *ITestNew()
{
	ITest *test = sys_malloc(sizeof(ITest));
	test->lpVtbl = sys_malloc(sizeof(ITestVtbl));
	test->lpVtbl->sayHello = ITest_sayHello;
	return test;
}

void main()
{
	ITest *test = ITestNew();
	test->answer = 42;
	test->sayHello();
}



The class name is ITest and you create it with ITestNew().
You can have fields and methods, so have fun with it.

Greetings
Felix


Visit my site: www.masterq32.de
Re: Research: How to do classes in Lite-C [Re: MasterQ32] #420057
03/19/13 08:42
03/19/13 08:42
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Very intereting. I did a search for further info about 'interface' keyword but did not find an explanation. Could you point us?

Thanks!

Re: Research: How to do classes in Lite-C [Re: MasterQ32] #420061
03/19/13 08:56
03/19/13 08:56
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
thanks. a while ago I thought of adding voids to a struct to elimitate some if-else branching. I would never find out that interface thingie...


Free world editor for 3D Gamestudio: MapBuilder Editor
Re: Research: How to do classes in Lite-C [Re: sivan] #420119
03/20/13 05:30
03/20/13 05:30
Joined: Apr 2006
Posts: 159
Latvija
Arrovs Offline
Member
Arrovs  Offline
Member

Joined: Apr 2006
Posts: 159
Latvija
I wish it could be possible like this:
http://www.pvv.org/~hakonhal/main.cgi/c/classes/

Possible it is, but im not found it in Lite-c.

I will sure test out interface, but i think it will not do everyhing what i want.


Arrovs once will publish game
Re: Research: How to do classes in Lite-C [Re: Arrovs] #420134
03/20/13 11:35
03/20/13 11:35
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline OP
Expert
MasterQ32  Offline OP
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
@Arrovs:
This is possible, but you need Lite-C syntax and pointers instead of normal c syntax and copying structs.

Interface could be found at "DLLs and API" in the manual but not very well documented.

@JustSid:
The function signature is copied from the manual, i didn't change that. Also this whole thing isn't compatible to MSVC at all i think. It appears that the Lite-C Compiler just takes the interface, adds -[>lpVtbl] to it and [&interface] as the first parameter of the function call.
And the member is in the vtbl because you cannot access if it is declared in the interface itself.


Visit my site: www.masterq32.de

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