module mod {
#define N
extern int var;
int func (...):
}
#include "lua.hpp"
#include "tlclass.h"
CDerived1 * toDerived1(void * p){
return dynamic_cast<CDerived1*>((CBase*)p); }
CDerived2 * toDerived2(void * p){
return dynamic_cast<CDerived2*>((CBase*)p); }
int tolua_calllua_open(lua_State*);
int _tmain(int argc, _TCHAR* argv[]){
lua_State * L = luaL_newstate();
luaopen_base(L);
tolua_calllua_open(L);
//call lua function
luaL_dofile(L, "..\scripts\CallLuaFunc.lua");
CBase * p1 = new CDerived1();
CBase * p2 = new CDerived2();
//call Derived1Test
lua_getglobal(L, "Derived1Test");
lua_pushlightuserdata(L, p1);
if( lua_pcall(L, 1, 0, 0) != 0 ) {
fprintf(stderr, "call Derived1Test failed:%s ", lua_tostring(L, -1)); }
//call Derived2Test
lua_getglobal(L, "Derived2Test");
lua_pushlightuserdata(L, p2);
if( lua_pcall(L, 1, 0, 0) != 0 ){
fprintf(stderr, "call Derived2Test failed:%s ", lua_tostring(L, -1));
}
printf("This info is print in C++! CDerived2.GetNumber()=%d ",
((CDerived2*)p2)->GetNumber());
delete p1;
delete p2;
lua_close(L);
return 0; }