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
0 registered members (), 1,094 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
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