tolua++编译

tolua++的源码可以从github上获取(https://github.com/LuaDist/toluapp)(目前的版本只支持5.0与5.1)

win32的编译可以直接在解压目录中的win32中的vc7中打开

将luaxlib.h,lua.h,luaconf.h,lualib.h放到include文件夹中,lua51.lib放在lib文件夹中进行编译,可能的修改一下Lib库的名字

在bin目录下会生成tolua++.exe文件

将test文件夹下的tarray.c,tarray.h,tarray.pkg放到bin进行编译导出

talua++.exe –o  lua_tarray.cpp tarray.pkg(编译导出指令)

生成一个lua_tarray.cpp临时文件 tarray.lua就是测试文件,可以进行导出的测试

pkg文件的编写规则:(cpp与h就是常规的一样,没啥区别,主要是根据pkg导出类型)

 

一个package文件可以包括其他的package文件。一般的格式是:

$pfile "include_file"

一个package文件同样可以包括一般的C/C++头文件,使用hfile或cfile指令:

$cfile "example.h"

在这种情况下, tolua将提取的代码封闭之间tolua_begin和tolua_end ,或tolua_export的一条直线上。以这个C++头为例思考:(注:这里并不是每个头文件都需要使用这些注释来告诉tolua要加入这些代码,仅仅是对于package文件包括的头文件而言)

 
#ifndef EXAMPLE_H
#define EXAMPLE_H
 
class Example { // tolua_export
 
private:
 
 string name;
 int number;
 
public:
 
 void set_number(int number);
 
 //tolua_begin
 
 string get_name();
 int get_number();
};
// tolua_end
 
#endif

 

In this case, the code that's not supported by tolua (the private part of the class), along with the function set_number is left outside of the package that includes this header.

最后,lua文件可以被包括在package文件里,使用$lfile:

$lfile "example.lua"

新的tolua++:自1.0.4版本以来的tolua++,提供了一个额外的方式可以包括源文件,使用ifile:

$ifile "filename"

ifile还额外的可选参数后的文件名(ifile also takes extra optional parameters after the filename),例如:

$ifile "widget.h", GUI
$ifile "vector.h", math, 3d

 

ifile的默认行为是包括整个文件的原样。但是,该文件的内容和额外的参数在被纳入package之前通过include_file_hook函数进行处理 (see Customizing tolua++ for more details)。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值