这是我在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. VIM小技巧之文件名补全

    恩,这两天在看<简明Python教程>,那里面作者建议写代码的时候前面的注释写上文件名,写上调用的解释器,比如这样: 恩,然后我当然不可能每回新建一个文件,就要在开头写上一大串东西啊,vi ...

  2. ORACLE 语句关联统计

    很久不用SQL语句了,貌似入职新公司后,又回归到了三年前的SQL时代,一写一坨的SQL好吧,也当回归一下过去的知识. 下面是统计2月份某数据的计费统计 select t.telno as 主号,VID ...

  3. 【原】使用ajax的get异常获取数据的时候,IE浏览器总是有缓存

    //HTML里有下面这样一段代码 //异步获取准备人信息 $.get("PrepSetpNew/PrepareMainCrew.ashx?Method=GetPrepUserInfo&quo ...

  4. silverlight 文本框只能输入数字

    void mobile_KeyUp(object sender, KeyEventArgs e) { Regex rg = new Regex("^[0-9]{1,11}$"); ...

  5. 为msysgit增加vim语法高亮文件

    在win7下装了msysgit,今天我遇到一个不爽的问题,打开git bash,用vim打开一个xml文件 结果都是黑屏的,没语法高亮,这个必须不能忍啊,我找到msysgit的安装目录,发现Vim73 ...

  6. 利用Jmeter做接口测试

    本文作者:大道测试团队-孙云 1.在安装jmeter之前先配置好JDK,再配置jmeter环境变量. 2.启动jmeter 启动jmeter: 双击Jmeter解压路径(apache-jmeter-3 ...

  7. python 内置模块之logging

    1.将日志直接输出到屏幕 import logging logging.debug('This is debug message') logging.info('This is info messag ...

  8. COUNT(*),count(1),COUNT(ALL expression),COUNT(DISTINCT expression)

    创建一个测试表 IF OBJECT_ID( 'dbo.T1' , 'U' )IS NOT NULL BEGIN DROP TABLE dbo.T1; END; GO )); GO INSERT INT ...

  9. 详解C/C++预处理器

     C/C++编译系统编译程序的过程为预处理.编译.链接.预处理器是在程序源文件被编译之前根据预处理指令对程序源文件进行处理的程序.预处理器指令以#号开头标识,末尾不包含分号.预处理命令不是C/C++语 ...

  10. iOS开发网络篇—大文件的多线程断点下载(转)

    http://www.cnblogs.com/wendingding/p/3947550.html   iOS开发网络篇—多线程断点下载 说明:本文介绍多线程断点下载.项目中使用了苹果自带的类,实现了 ...