Skip to content

Instantly share code, notes, and snippets.

@marcoleong
Created December 16, 2011 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcoleong/1485099 to your computer and use it in GitHub Desktop.
Save marcoleong/1485099 to your computer and use it in GitHub Desktop.
Use this to load Lua
#include "tolua++.h"
#include "Scene.h"
char* Scene::getData() {
printf("Something %s",data);
return data;
}
void Scene::setData(const char* pData){
sprintf(data, "%s",pData);
}
static int tolua_new_Scene(lua_State* tolua_S){
Scene* pScene = new Scene();
tolua_pushusertype(tolua_S, pScene, "Scene");
return 1;
}
static int tolua_delete_Scene(lua_State* tolua_S){
Scene* pScene = (Scene* )tolua_tousertype(tolua_S, 1, 0);
if (NULL != pScene)
{
delete pScene;
}
return 1;
}
static int tolua_setData_Scene(lua_State* tolua_S){
Scene* pScene = (Scene* )tolua_tousertype(tolua_S, 1, 0);
const char* pData = tolua_tostring(tolua_S, 2, 0);
if(pData != NULL && pScene != NULL)
{
pScene->setData(pData);
}
return 1;
}
static int tolua_getData_Scene(lua_State* tolua_S)
{
Scene* pScene = (Scene* )tolua_tousertype(tolua_S, 1, 0);
if(pScene != NULL)
{
char* pData = pScene->getData();
tolua_pushstring(tolua_S, pData);
}
return 1;
}
TOLUA_API int tolua_Scene_open (lua_State* tolua_S) {
tolua_open(tolua_S);
tolua_module(tolua_S,NULL,0);
tolua_beginmodule(tolua_S, NULL);
tolua_usertype(tolua_S, "Scene");
tolua_cclass(tolua_S, "Scene", "Scene", "", tolua_delete_Scene);
tolua_beginmodule(tolua_S, "Scene");
tolua_function(tolua_S, "new", tolua_new_Scene);
tolua_function(tolua_S, "setData", tolua_setData_Scene);
tolua_function(tolua_S, "getData", tolua_getData_Scene);
tolua_endmodule(tolua_S);
tolua_endmodule(tolua_S);
return 1;
}
#ifndef TheArena_Scene_h
#define TheArena_Scene_h
class Scene
{
public:
char* getData();
void setData(const char* data);
private:
char data[200];
};
int tolua_Scene_open(lua_State* tolua_S);
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment