Quote:

This thread might be of interest to you:
http://www.coniserver.net/ubbthreads/sho...true#Post809004

excessus:
Quote:


Since Lite-C is a little weird about function pointers (they're not actually types, I think), you can't have a function pointer type in your struct. But you can have a void* in which you can store (but not call) a function pointer (manual suggests you do this for function pointer arrays, so it's not THAT unsafe). You can then assign the void* to a function pointer (Lite-C casts automatically), and call the function from the function pointer.

This basicly gives you member functions, but the syntax is quite ugly. Maybe you can fix that with a macro. CALL_MEMBER or something..





He provides an example as well.

Greetz




Hm thats weird. It feels like im doing the same thing but it wont work.
Take a look at this:

Code:

#include <acknex.h>
#include <default.c>

#define new(TYPE) malloc(sizeof(TYPE))
#define delete(OBJECT) free(OBJECT)

typedef struct
{
int id;
var coolness;
STRING* name;
function lolz();
} ITEM;

ITEM* obj1;

function init_item(ITEM* item, var coolness, STRING* name)
{
static int count = -1;
item.id = ++count;
item.coolness = coolness;
item.name = name;
}

TEXT* pnl =
{
pos_x = 10;
pos_y = 10;
flags = VISIBLE;
}

function test()
{
(pnl.pstring)[0] = "performed";
}

function perform()
{
obj1.lolz();
}

function main()
{
screen_color.blue = 155;

obj1 = new(ITEM);
init_item(obj1, 2, "Hej");
obj1.lolz = test;

on_a = perform;
}