最近在学LUA,想写个游戏,练习LUA的应用,在网上翻了好几天,
终于找到了适合的游戏开发库,配置好了游戏开发环境,真的不太容易,
网上资料也都太杂了,所以在这里分享一下我自己整理的开发环境配置,
希望能给同需要的人提供一些思路和启发。
——————————————————————————————————————————————————————————————————
一、开发工具:
1、 VS2008 C/C++
2、VS扩展库:(下列库的源码和编译方法网上都能找到,此处略)
- Lua5.1 (需要本机编译)
- Luabind-0.9(需要本机编译)
- Hge1.8.1(不用本机编译)
- Boost1.40.0(需要本机编译)
二、配置环境:
1、添加环境变量:
LUA_PATH C:/Program Files/Lua/5.1/
HGE_DEV D:/LUA/GameDev/hge181
BOOST_ROOT E:/boost-1.40.0.cmake2
(这几个扩展库的位置可以自己定,我因为有其他开发项目要用到同样的库,所以看着放的比较乱)
2、 配置VS环境:
1) 添加项目包含目录和库目录
包含目录: $(LUA_PATH)include
$(BOOST_ROOT)
$( HGE_DEV)include
库目录: $(LUA_PATH)lib
$(HGE_DEV) lib/vc
$(BOOST_ROOT)/libs/regex/build/vc90
2) 把hge.dll和bass.dll复制到系统/WINDOWS/system32下;(其他方法待研究)
3) 创建一个win32控制台应用程序(空项目即可)
4) 添加项目属性:
路径:添加Luabind-0.9所在目录:例如:D:/LUA/luabind-0.9
依赖库:lua51.lib hge.lib hgehelp.lib
5) 把luabind-0.9/src文件夹下的源程序包含到工程中;(为了提高编译速度,可以把luabind-0.9编译成静态库,链接到工程中)
6) 新建一个主程序文件main.cpp
7) 在main.cpp中添加如下:
#include
/*Include lua header file*/
#ifdef __cplusplus
extern "C"{
#endif
#include
#include
#include
#ifdef __cplusplus
}
#endif
/*Include LuaBind header file*/
#include "luabind-0.9/luabind/luabind.hpp"
/*Include HGE header file*/
#include
8) 写一个C/C++的入口函数,main(),现在可以编译了。
9) 写一个Hello world的例子,测试环境:
#include
#include
#include
/*Include lua header file*/
#ifdef __cplusplus
extern "C"{
#endif
#include
#include
#include
#ifdef __cplusplus
}
#endif
/*Include LuaBind header file*/
#include "luabind-0.9/luabind/luabind.hpp"
/*Include HGE header file*/
#include
/*Global variables */
using namespace std;
lua_State *L = NULL;
/*C/C++ Interface for lua to call*/
void greet(void)
{
cout << "Luabind execute successfully!" << endl;
}
extern "C" int First(lua_State* L)
{
luabind::open(L);
luabind::module(L)
[
luabind::def("Greet", &greet)
];
return 0;
}
/*Entry function*/
int main(int args, char *argc)
{
char acBuf[1024] = {'/0'};
int nErr = 0;
cout<<"********** Small Game v0.1 ***********"<>Greet()
Luabind execute successfully!
>>
————————————————————————————————————————————————————————————————
相关资料和库源码下载网站推荐:
1、《LuabindManualCN.pdf》
2、http://www.lua.org/
3、http://www.boost.org/
4、http://hge.relishgames.com/
至此,我们就配置好了利用lua和hge引擎开发2D游戏的一个平台
在此分享的是配置环境的大体过程,按照此每一步设置,那一步不理解可以在网上找到方法,我就没有赘述,
先分享到这儿,有不明白的可以联系,一起学习进步,有写得不妥之处也请谅解!