[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: lua++
- From: "Victor" <victorio@...>
- Date: Mon, 14 May 2001 15:35:12 -0000
Hi everyone!
I use Lua often in c++ programs, and always when my program was multistage
then I've problems to do it with Lua, because there is no
possibility to indicate Lua c-function what state (of my program) is used.
i.e.
class aClass;
and objects:
aClass a,b,c;
and states of lua L1,L2 and L3
then there is no possibility to tell lua that L1 may to call method i.e.
foo() from object a, and
L2 method foo() from object b.
Then I've extend Lua 4.0 to register object methods, just like this:
#include "lua.h"
#include <stdio.h>
/*********
Class must be inherited from LuaBaseClass
*********/
class mClass:public LuaBaseClass
{
public:
mClass()
{
L = lua_open(1024); /* create state */
lua_registercpp(L,"testcpp",mClass::testcpp); /* register member from
this object */
};
~mClass() {lua_close(L);};
int testcpp(lua_State * L) {printf("test function called\n"); return
0;};
void DoString(char * s) {lua_dostring(L,s);};
private:
lua_State * L;
};
int main(void)
{
mClass a;
while (1)
{
char buf[1000];
fgets(buf,1000,stdin);
a.DoString(buf);
}
return 0;
}
so, if anybody interested to get lua with this extension, source code is
avaible on address:
http://strony.wp.pl/wp/artur.keska/
All my changes are excluded by "#ifdef CPP_EXTENSION", so this version of
Lua could be compiled
like normal version, if CPP_EXTENSION is not defined.