展开全部
第一步:看cocos2dx调用lua的最初切入点:
[cpp] view plain copy
bool AppDelegate::applicationDidFinishLaunching()
{
CCDirector *pDirector = CCDirector::sharedDirector();
pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320, kResolutionNoBorder);
pDirector->setDisplayStats(true);
pDirector->setAnimationInterval(1.0 / 60);
// register lua engine
CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();//从这里开62616964757a686964616fe78988e69d8331333363366231始了lua旅程。
CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine);//保存刚才新建的lua引擎对象,以便别处调用。
std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("hello.lua");//CCFileUtils工具类一定封装了文件的搜索路径。
//接下来直接执行了脚本,跟句helloCpp工程的实现,这里本该是类似
//CCScene *pScene = HelloWorld::scene();
//pDirector->runWithScene(pScene);
//这样的代码,但这里并没有这样的代码,可以猜测:hello.lua中一定是实现了类似这样的一些功能,事实上,一定是这样。
//---因为需要添加的这些东西scene、other nodes都是一些c++类的对象,
//既然hello.lua能完成这些工作,那么lua也一定是有能力访问并操作了这些类与对象,
//换句话说,也就是一定存在一种机制,让c+