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 ...
随机推荐
- 【转】asp.net mvc3 简单缓存实现sql依赖
asp.net mvc3 简单缓存实现sql依赖 议题 随 着网站的发展,大量用户访问流行内容和动态内容,这两个方面的因素会增加平均的载入时间,给Web服务器和数据库服务器造成大量的请求压力.而大 ...
- 记一次linux samba服务问题调试
linux下samba服务加入windows域控后,samba共享名与合法用户名不应一致,否则无法访问此共享.
- 重写DataGridViewColumn
做个项目需要用到DataGridView,这个控件还是挺好用的,但是今天却发现无法实现自己想要的功能.主要是DataGridViewCheckBoxColumn这个列虽然是提供了复选框,但是却未能在复 ...
- Redis源码研究--跳表
-------------6月29日-------------------- 简单看了下跳表这一数据结构,理解起来很真实,效率可以和红黑树相比.我就喜欢这样的. typedef struct zski ...
- Discuz X3.2 SEO设置 title 不支持空格的解决方法
很多使用 Discuz X3.2 的同学都发现这么一个问题:在后台SEO设置-title设定的时候,即使你在连字符两侧输入了空格,在前台也显示不出来,很多同学纠结这个问题,今天终于找到了解决方法,在此 ...
- python: 实现sha1小工具
File1: sha1.py File2: sha1.bat ------------------ File1: sha1.py import hashlib import os,sys def Ca ...
- 简单的Datatable转List,Json
这里用到了Newtonsoft.Json,下载地址:http://json.codeplex.com/ 1.根据不同的Model转为对应的List public static List<Mode ...
- vim使用手册
1. 关于Vim 1.1 Vim的几种模式 2. 启动Vim 3. 文档操作 4. 光标的移动 4.1 基本移动 4.2 翻屏 4.3 标记 5. 插入文本 5.1 基本插入 5.2 改写插入 6. ...
- zip压缩包密码破解
有一种破解方法叫做Known plaintext attack.市面上的密码破解软件几乎都带有这个功能.操作方法就是找到加密压缩包中的任意一个文件,用同样的压缩软件同样的压缩方式压缩成一个不加密的包, ...
- 2016 系统设计第一期 (档案一)jQuery checkbox 取值赋值
<div class="form-group"> <label for="IsActive" class="col-sm-2 con ...