cocos2d-x + Lua(2) C++和lua数据通讯之间的互调(2)
来源:未知 责任编辑:责任编辑 发表时间:2014-05-10 12:17 点击:次
p>
p>
p>private:
p>
p> static bool _isFirst;
p> static PublicSendLuaData* m_instance;
p> const char* getFileFullPath(const char* fileName);
p> ~PublicSendLuaData();
p>};
p>
p>#endif
p>复制代码
p>PublicSendLuaData.cpp
p>
p>复制代码
p>// PublicSendLuaData.cpp
p>//
p>// Created by ZISOU-YSJ
p>//
p>// Lua and C++/c 交互类
p>
p>#include "PublicSendLuaData.h"
p>#include "CCLuaEngine.h"
p>
p>PublicSendLuaData* PublicSendLuaData::m_instance = NULL;
p>PublicSendLuaData* PublicSendLuaData::getInstance(){
p> if(!m_instance)
p> {
p>
p> m_instance = new PublicSendLuaData();
p> }
p> return m_instance;
p>}
p>//获取变量名值
p>const char* PublicSendLuaData::getLuaVarString(const char* luaFileName,const char* varName){
p>
p> lua_State* ls = CCLuaEngine::defaultEngine()->getLuaStack()->getLuaState();
p>
p> int isOpen = luaL_dofile(ls, getFileFullPath(luaFileName));
p> if(isOpen!=0){
p> CCLOG("Open Lua Error: %i", isOpen);
p> return NULL;
p> }
p>
p> lua_settop(ls, 0);
p> lua_getglobal(ls, varName);
p>
p> int statesCode = lua_isstring(ls, 1);
p> if(statesCode!=1){
p> CCLOG("Open Lua Error: %i", statesCode);
p> return NULL;
p> }
p>
p> const char* str = lua_tostring(ls, 1);
p> lua_pop(ls, 1);
p>
p> return str;
p>}
p>
p>const char* PublicSendLuaData::getLuaVarOneOfTable(const char* luaFileName,const char* varName,const char* keyName){
p>
p> lua_State* ls = CCLuaEngine::defaultEngine()->getLuaStack()->getLuaState();
p>
p> int isOpen = luaL_dofile(ls, getFileFullPath(luaFileName));
p> if(isOpen!=0){
p> CCLOG("Open Lua Error: %i", isOpen);
p> return NULL;
p> }
p>
p> lua_getglobal(ls, varName);
p>
p> int statesCode = lua_istable(ls, -1);
p> if(statesCode!=1){
p> CCLOG("Open Lua Error: %i", statesCode);
p> return NULL;
p> }
p>
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>