tolua++ 编译 及使用 简单介绍
2017-07-06 15:25
330 查看
tolua++ 编译 及使用 简单介绍
标签: tolua++luaC++2015-11-03 00:52 1594人阅读 评论(0) 收藏 举报
分类:
Lua(6)
版权声明:本文转自http://blog.csdn.net/huutu 转载请带上 http://www.thisisgame.com.cn
tolua++ 是用来把 C++代码 生成 在Lua中使用的接口的工具,编译步骤比较繁琐。
1、下载lua5.1.4,解压后,新建空项目,修改成静态库lib ,在C++ 代码生成选项卡 中设置 运行库 为 多线程 DLL (/MD) ,然后把安全检查 设置为 禁用安全检查 (/GS-)
把lua5.1.4 src目录下的 除了 lua.c luac.c 的所有文件添加到项目中,编译。
编译成功后获得 lua5.1.4.lib 。
2、下载 tolua++ ,解压后,新建空项目,其它设置和上面一样,添加 tolua++ 文件夹中的 src/lib/ 里面的所有代码到项目中,编译成静态库。
编译成功后获得 tolua++.lib
到 tolua++ 文件夹中的 win32/vc7 中,打开 toluaapp.sln ,设置好 lua 头文件目录,把lua5.1.4.lib 添加到链接库 ,添加 tolua++ 目录的include 目录到头文件目录,把 tolua++.lib 添加到链接库,编译。
编译成功后,在tolua++目录的bin 中获得 tolua++.exe
3、编写Student 类来作为测试
Student.h
[cpp] view
plain copy
#pragma once
#include<iostream>
using namespace std;
class Student
{
public:
Student();
~Student();
void Run();
void Run(int a);
};
Student.cpp
[cpp] view
plain copy
#include "Student.h"
Student::Student()
{
}
void Student::Run()
{
cout << "Student Run" << endl;
}
void Student::Run(int a)
{
cout << "Student Run" <<a<< endl;
}
Student::~Student()
{
}
为Student 类创建 pkg文件
Student.pkg
[html] view
plain copy
$#include"Student.h"
class Student
{
public:
Student();
~Student();
void Run();
void Run @ Run2(int a);
};
把tolua++.exe 到 Student 的类文件目录,右键命令行
[html] view
plain copy
"tolua++.exe" -o lua_Student.cpp Student.pkg
生成成功获得 lua_Student.cpp
4、创建测试项目在lua 脚本中使用 Student 类
创建空项目,项目中设置好 lua5.1.4 和 tolua++ 的头文件目录 ,以及引用 lua5.1.4.lib 和 tolua++.lib 。
然后把 Student 类 和生成的 lua_Student.cpp 添加到项目中。
main.cpp
[cpp] view
plain copy
#include <stdio.h>
#include<windows.h>
extern "C"
{
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include "luaconf.h"
}
#include "tolua++.h"
#include"Student.h"
extern int tolua_Student_open(lua_State* tolua_S);
int main(int argc, char* argv[])
{
lua_State* L = luaL_newstate();
luaL_openlibs(L);
tolua_Student_open(L);
luaL_dofile(L, "./test.lua");
lua_close(L);
system("pause");
return 0;
}
lua脚本文件 test.lua
[html] view
plain copy
studentB=Student:new() --实例化Student全局对象
function Run()
studentB:Run();
end
function Run2(a)
studentB:Run2(a);
end
function show()
local b = {}
local index
for index = 1,10,1 do
print(index)
end
end
show()
Run()
Run2(10)
项目打包下载 (lua5.1.4 + luajit + toluapp)
百度网盘:
[html] view
plain copy
http://pan.baidu.com/s/1i3xvykt
CSDN下载:
[html] view
plain copy
http://download.csdn.net/detail/cp790621656/9235459
相关文章推荐
- tolua++ 编译 及使用 简单介绍
- tolua++ 编译 及使用 简单介绍 标签: tolua++luaC++
- MagicAjax 简单使用介绍(翻译)
- linux file.src.rpm 使用方法的简单介绍
- tcpdump 工具简单使用介绍
- 使用技巧:简单介绍JSP数据库高级操作
- 本文介绍在VC 6.0中编译和使用OpenSSL的过程
- DirectX 9高层着色语言介绍1 —— 引言、简单例子、汇编语言和编译对象
- Asp.net 2.0中Themes的使用简单介绍
- 简单介绍 VC2003 使用 ATL 开发 ActiveX 控件
- 软件包管理 之 file.src.rpm 使用方法的简单介绍
- 【ABAP】LSMW使用IDoc方法的简单介绍
- Oracle游标使用的简单介绍
- [转]Java的开源项目:简单介绍Log4J的使用
- [转]Java的开源项目:简单介绍Log4J的使用
- Java线程简单使用介绍zz
- 一个简单的动态编译器,支持C#和VB.NET。当你想测试一些简单的代码的时候可以使用。
- CProgressCtrl 进度条控件的使用方法简单介绍
- 简单介绍vss工具command操作使用
- Linux curl使用简单介绍