这是我在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的更多相关文章

  1. lua function

    This is the main reference for the World of Warcraft Lua Runtime. Note that these are mostly standar ...

  2. Lua function 函数

    Lua支持面向对象,操作符为冒号‘:’.o:foo(x) <==> o.foo(o, x). Lua程序可以调用C语言或者Lua实现的函数.Lua基础库中的所有函数都是用C实现的.但这些细 ...

  3. call lua function from c and called back to c

    Just a simple example: --The  c file: #include <stdio.h> #include "lua.h" #include & ...

  4. lua解释执行脚本流程

    #include "lua.hpp" #include <iostream> using namespace std; #pragma comment(lib, &qu ...

  5. lua 环境揭秘

    什么是环境? http://www.lua.org/manual/5.1/manual.html#2.9 Besides metatables, objects of types thread, fu ...

  6. Lua 5.1 参考手册

    Lua 5.1 参考手册 by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes 云风 译 www.codingno ...

  7. Lua 架构 The Lua Architecture

    转载自:http://magicpanda.net/2010/10/lua%E6%9E%B6%E6%9E%84%E6%96%87%E6%A1%A3/ Lua架构文档(翻译) 十 102010 前段时间 ...

  8. Lua的协程(coroutine)

    -------------------------------------------------------------------------------- -- 不携带参数 ---------- ...

  9. 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 ...

随机推荐

  1. COM包装(COM Wrappers)

    为了实现传统的COM程序与.NET程序之间的相互调用,.NET提供了两个包装类:运行时可调用包装(runtime callable wrapper,RCW)和COM可调用包装(COM callable ...

  2. ListBox复选框拓展

    Toolkit的LongListMutiSelector的复选框功能,想必许多人都需要吧!然而系统本身控件ListBox虽然也有多选功能,可是外观上却缺乏复选框,选择效果只是颜色变化.于是在上一个项目 ...

  3. 私人定制自己的linux小系统

     私人定制自己的linux小系统 一.前言    linux操作系统至1991.10.5号诞生以来,就源其开源性和自由性得到了很多技术大牛的青睐,每个linux爱好者都为其贡献了自己的一份力,不管是在 ...

  4. file与 byte[] 互转

    byte 转file String filepath="D:\\"+getName();          File file=new File(filepath);        ...

  5. 身处IT的你对身边人都有哪些影响

    前不久,跟外甥一起吃饭:他明年就要中考了,我就想,这马上就到人生的关键路口了,看他自己对将来有什么想法没:就问了句:勇勇,你以后想学习哪些方面的东西或者想从事什么工作呢?他简单的说了句:我要跟你一样学 ...

  6. linux服务器修改ssh默认22端口方法

    1.登录服务器,打开sshd_config文件 # vim /etc/ssh/sshd_config 2.找到#Port 22,默认是注释掉的,先把前面的#号去掉,再插入一行设置成你想要的端口号,注意 ...

  7. 分享:mysql 随机查询数据

    在mysql中查询5条不重复的数据,使用以下: 1 SELECT * FROM `table` ORDER BY RAND() LIMIT 5  就可以了.但是真正测试一下才发现这样效率非常低.一个1 ...

  8. C# 链接Sql和Access数据库语句

    1.sql数据库: 1.1.链接数据语句:server=localhost;database=Data; uid=sa;pwd=123; 或 Data Source=localhost;DataBas ...

  9. 8、WPF体系架构和运行机制

    体系架构:http://msdn.microsoft.com/zh-cn/library/ms750441.aspx 运行机制:http://www.cnblogs.com/leep2007/arch ...

  10. DBus通讯

    linux下进程间通信的方式主要有Pipe(管道),FIFO(命名管道),信号,共享内存,消息队列,信号灯等,这些方式各有 各得特点,如管道是linux下命令行中常用的,用于父子进程的通信.但是这些通 ...