温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

cocos2dx 暴露c++函数给lua

发布时间:2020-06-30 17:10:17 来源:网络 阅读:586 作者:zswnet 栏目:开发技术

1 tolua++ 目录下创建一个目录zgame


编写zgExtension.pkg

$#include "ZgExtension.h"
$pfile "zgame/ZgameAnimation.pkg"
$pfile "zgame/TableView.pkg"
$pfile "zgame/Zgame.pkg"
$pfile "zgame/GraySprite.pkg"


再增加其他的pkg文件, 目的是将几个c++文件, 打包成一个ZgExtension.cpp文件


2 编辑basic.lua, 增加子pkg文件, 然后运行build.sh, 就会生成ZgExtension.cpp文件



3. 编辑ZgExtension.h文件

#ifndef __LUAzsw_H_
#define __LUAzsw_H_
extern "C" {
#include "tolua++.h"
#include "tolua_fix.h"
}
#include <map>
#include <string>
#include "tolua_fix.h"
#include "cocos2d.h"
#include "CCLuaEngine.h"
#include "SimpleAudioEngine.h"
#include "ZgameAnimation.h"
//#include "luaCCBLayer.h"
//#include "luaShadeCCBLayer.h"
#include "TableView.h"
#include "zgame.h"
#include "GraySprite.h"
#include "cocos-ext.h"
//#include "CCEditBox.h"ddaaaaadddwasd
#ifndef __cplusplus
#include "stdlib.h"
#endif
#include "string.h"
#include "tolua++.h"
using namespace cocos2d;
using namespace CocosDenshion;
TOLUA_API int tolua_ZgExtension_open(lua_State* tolua_S);
#endif // __LUAzsw_H_


4. 将这2个文件放到项目工程自己的toLua的目录下, 然后在MainGame.cpp(AppDelegate.cpp),加上

#include "toLua/ZgExtension.h"


lua中就可以调用到c++的函数了

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI