# Include "stdaf. H"
Extern "C"
{
# Include "Lua. H"
# Include "lualib. H"
# Include "lauxlib. H"
}
# Include "tolua ++. H"
# Include "test. H"
# Include "CLS"
Int _ tmain (INT argc, _ tchar * argv [])
{
Cppclass * PCLs = new cppclass;
// Init
Lua_state * pluastate = NULL;
Pluastate = lua_open ();
Lual_openlibs (pluastate );
// Using PKG to bind
Tolua_tet_open (pluastate );
// Load
Int status = 0;
Status = lual_loadfile (pluastate, "test. Lua ");
// Call
If (status -- 0)
{
Status = lua_pcall (pluastate, 0, lua_multret, 0 );
Lua_getglobal (pluastate, PCLS );
Int ret = lua_pcall (pluastate, 1, 0, 0 );
Int A = ret;
}
Else
{
Printf ("Something is wrong \ n ");
}
// Clear the stack
Lua_settop (pluastate,-2 );
// Close state
Lua_close (pluastate );
Delete PCLs;
Return 0;
}
This is the approximate code for C ++ and tolua ++ to call each other.
PCLs is a class
Tolua_tet_open (pluastate); in this example, tolua_xxxxxx_open xxxxxx is the name of PKG, Which is test. PKG.