首页 技术 正文
技术 2022年11月14日
0 收藏 322 点赞 4,188 浏览 1650 个字

一) 、建立lua源代码工程,编译lua的静态库

1、下载Lua源码 http://www.lua.org/download.html

a 下载后解压到一个目录下,这里假设解压到D:\lua-5.1.5b 注意下载的版本,如果是5.2.x,后面代码中的C API发生了改变
2、在VS2010中新建一个静态库项目,项目命名为lua
     a 选择新建 Win32 console project
     b 在wizard界面选择 static Library;不选择Precomplied Header
3、往工程中添加代码(Add -> Existing Item)
     a 添加D:\lua-5.1.5\src 目录下的*.h文件到项目的Header Files目录下
     b 添加D:\lua-5.1.5\src 目录下的*.c文件到项目的Source Files目录下
(可选)4、配置项目的属性,在项目的“配置属性” 界面中操作
    a Configuration Properties -> C/C++-> General -> Additional Include Directories 
       添加D:\lua-5.1.5\src
    b Configuration Properties -> C/C++-> Advanced -> compile as 
        这里的选择将影响后面代码中如何指定编译链接方式,后面的测试选择的是Compile as C code
(可选)5、 生产项目 Build
     如果是DEBUG mode 将在Debug目录下看到一个lua.lib文件,Release mode的lib文件在Release文件下

二)、后面添加一个项目尝试在C/C++代码中, 调用刚才的lua静态库
1、在解决方案中添加一个 Win32 console project,项目名称命名为testlua,后面wizard界面中的选项无需修改
2、添加对lua项目的引用
    a Common Properties -> Framework and References -> Add New References 
   选择lua项目
3、添加对头文件的include directory
   a Configuration Properties -> C/C++-> General -> Additional Include Directories 
  添加D:\lua-5.1.5\src
4、在项目的的在testlua.cpp文件中添加下面的代码

  1. #include “stdafx.h”
  2. #include <stdio.h>
  3. #include <string.h>
  4. extern “C”
  5. {
  6. #include <lua.h>
  7. #include <lualib.h>
  8. #include <lauxlib.h>
  9. }
  10. int _tmain(int argc, _TCHAR* argv[])
  11. {
  12. lua_State *L = lua_open();
  13. luaL_openlibs(L);
  14. const char *buf = “print(‘Hello World’)”;
  15. luaL_dostring(L,buf);
  16. lua_close(L);
  17. getc(stdin);
  18. return 0;
  19. }

VS2010编译、调用Lua程序

5,设置默认的项目,否则要去手动运行生成的可执行文件testlua.exe (见附图)
     Solution -> Properties -> Common Properties ->Startup Project ->Single startup project
     把默认的lua改为testlua
按F5或Ctrl+F5,将会在控制台中输入了Hello World。

来自:http://blog.csdn.net/berdy/article/details/7925040

附图1:在一个项目中添加另一个项目

VS2010编译、调用Lua程序

附图2: 设置默认项目

VS2010编译、调用Lua程序

附图3:静态库

VS2010编译、调用Lua程序       或者       VS2010编译、调用Lua程序  http://blog.csdn.net/appletreesujie/article/details/12065369 

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,942
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,468
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,281
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,095
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,728
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,765