自定义c++代码给lua用的一些细节总结
参考:点击打开链接
1.自定义 XXX.cpp . XXX.h2.D:\quick\quick-cocos2d-x-2.2.3-rc\lib\cocos2d-x\external\extra\luabinding
创建 XXX_luabinding.tolua$#include "XXX.h"
class XXX
{
static int getFileData();//根据自己具体写的去编写};
创建 build_ XXX_luabinding.bat
@echo off
set DIR=%~dp0
set OUTPUT_DIR=%DIR%
set MAKE_LUABINDING="%QUICK_COCOS2DX_ROOT%\bin\compile_luabinding.bat"
pushd
cd "%DIR%"
call %MAKE_LUABINDING% -E XXX -d %OUTPUT_DIR% XXX_luabinding.tolua
echo.
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo.
rem call %MAKE_LUABINDING% -d %OUTPUT_DIR% cocos2dx_extra_ios_iap_luabinding.tolua
popd
修改build.bat
在最下面添加
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo.
call %MAKE_LUABINDING% -d %OUTPUT_DIR% XXX_luabinding.tolua
3.运行build.bat
在模拟器的工程中添加对应的 XXX.cpp XXX.h 和生成的 XXX_luabinding.cpp 和 XXX_luabinding.h
4.在D:\quick\quick-cocos2d-x-2.2.3-rc\lib\cocos2d-x\scripting\lua\cocos2dx_support
CCLuaStack.cpp中
添加 67行
#include "MyHelperFunc_luabinding.h"
添加
bool CCLuaStack::init(void)中137行添加
luaopen_XXX_luabinding(m_state);
编辑模拟器,找到生成的替换win目录下的player.exe及附带资源
在运行自己的lua代码,生成成功。