First Lua function running in C
这是我在C里面跑出来的第一个Lua 文件, 纪念一下。
1.Set up envirnonment:
Mac下面 Lua的src (即include) 和lib(binary)是分开的, 所以需要分别下载。

使用的是 5.2.3 的src 和 standard lib(5.2.1_MacOS107_lib).
include 和 lib 在gcc 编译的时候需要用-L 引入。
2.代码:
VERY IMPORTANT:
ua_open() should not be used. In lua-5.1 it's still available as simple wrapper macro for luaL_newstate(). In lua-5.2 it doesn't exist at all. Attached patch replaces lua_open() call in freeciv code with luaL_newstate() call that works with both lua-5.1 and lua-5.2.
所以 之前写的程序有问题。
改写程序之后 才能run。
gcc :
gcc -o HelloMac main.c -L/Users/***/Downloads/lua-5.2.1_MacOS107_lib/include/ -L/Users/***/Documents/lua-5.2.3/src/ -llua
代码如下:
#include <stdio.h>
#include <string.h>
#include "/Users/***/Documents/lua-5.2.3/src/lua.h"
#include "/Users/***/Documents/lua-5.2.3/src/lauxlib.h"
#include "/Users/***/Documents/lua-5.2.3/src/lualib.h" int main (void) {
lua_State *L = luaL_newstate(); /* opens Lua */
luaL_openlibs(L); luaL_dostring(L, "a = 10 + 5");
lua_getglobal(L, "a");
int i = (int)lua_tointeger(L, -);
printf("%d\n", i); lua_close(L);
return ;
}
First Lua function running in C的更多相关文章
- lua function
This is the main reference for the World of Warcraft Lua Runtime. Note that these are mostly standar ...
- Lua function 函数
Lua支持面向对象,操作符为冒号‘:’.o:foo(x) <==> o.foo(o, x). Lua程序可以调用C语言或者Lua实现的函数.Lua基础库中的所有函数都是用C实现的.但这些细 ...
- call lua function from c and called back to c
Just a simple example: --The c file: #include <stdio.h> #include "lua.h" #include & ...
- lua解释执行脚本流程
#include "lua.hpp" #include <iostream> using namespace std; #pragma comment(lib, &qu ...
- lua 环境揭秘
什么是环境? http://www.lua.org/manual/5.1/manual.html#2.9 Besides metatables, objects of types thread, fu ...
- Lua 5.1 参考手册
Lua 5.1 参考手册 by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes 云风 译 www.codingno ...
- Lua 架构 The Lua Architecture
转载自:http://magicpanda.net/2010/10/lua%E6%9E%B6%E6%9E%84%E6%96%87%E6%A1%A3/ Lua架构文档(翻译) 十 102010 前段时间 ...
- Lua的协程(coroutine)
-------------------------------------------------------------------------------- -- 不携带参数 ---------- ...
- Calling Lua From a C Program
Introduction From a running C program, you can call a Lua script. The C program can pass arguments t ...
随机推荐
- The New Debugger
在debug下有一个中文叫做杂项的选项卡下有配置的内容 里面可以配置debug的模式 有的时候一些莫名其妙的问题需要 调整里面的设置 <<SAP debug的几种方式.pdf>> ...
- Android 技术用于汇总
id 名词 含义 详细 1 Android CTS CTS 全称 Compatibility Test Suite 兼容性测试工具 当产品开发出来以后,并定制了自己的 Android 系统后 ...
- JavaScript 内部对象
欢迎访问我的个人博客:http://blog.cdswyda.com/ 原文文地址:JavaScript 内部对象
- Centos6.4版本下搭建LAMP环境
Centos6.4版本下搭建LAMP环境 配置yum mkdir/mnt/cdrom mount/dev/cdrom /mnt/cdrom 装载光盘 vi /etc/yum.repos.d/Cent ...
- 33选6算法:M个数N个为一组,无重复的排列组合
private void button1_Click(object sender, EventArgs e) { int nCnt = 0; List nNumList = new List(); f ...
- 为 WordPress 标签添加 rel="nofollow" 属性
WordPress 标签默认并无 rel="nofollow" 属性.rel="nofollow" 属性的作用是:告诉搜索引擎,无需追踪目标页,禁止蜘蛛爬行和传 ...
- mysql rand随机查询记录效率
一直以为mysql随机查询几条数据,就用 SELECT * FROM `table` ORDER BY RAND() LIMIT 5 就可以了. 但是真正测试一下才发现这样效率非常低.一个15万余条的 ...
- lnmp下用phpize动态安装PHP模块/扩展(不需要重装PHP)
安装前 安装前建议先执行 /usr/local/php/bin/php -m (此命令显示目前已经安装好的PHP模块)看一下,要安装的模块是否已安装.然后下载当前PHP版本的源码并解压. 本文以ima ...
- 飞行器的Pitch Yaw Roll概念图解
前进方向为Z轴 Pitch 升降 绕X轴 对应常见Φ(phi)角: Yaw 偏航 绕Y轴 对应常见θ(theta)角: Roll 翻滚 绕Z轴 对应常见φ(psi)角: 对应表: 参考网址NASA: ...
- javascript和jquery 获取触发事件的元素
一个很简单的问题,却因为大意,经常忘了处理,导致程序运行出错. <!DOCTYPE html> <html> <head> <meta charset=&qu ...