这是我在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. 使用CInternetSession CHttpFile下载网页链接地址的文件

    思路很清晰,使用CInternetSession创建CHttpFile对象.然后对该对象获取文件信息.进行文件读写操作均可. void DownloadFile(LPCTSTR szURL, LPCT ...

  2. bootstrap2.3.2 modal 用href时有缓存

    $('body').on('hidden', '.modal', function () {$(this).removeData('modal');}); 直接在js里加入上面的代码就可以解决缓存问题 ...

  3. 如何设置fedora默认从命令行启动?

    Sumary:因为在fedora中没有/etc/initab文件我们不方便从这里设置它的runlevel target,但是linux又给我们提供了一个强悍的工具systemd,我们可以用system ...

  4. JQuery 表格 隔行换色 和鼠标滑过的样式

    $(document).ready(function () { $(".Pub_TB tbody tr:even td").css("background-color&q ...

  5. aspx返回json数据

    JQuery.getJSON 从aspx页面返回JSON数据 . -- ::| 分类: asp.net |举报|字号 订阅 . 发送请求的WebForm1.aspx <%@ Page Langu ...

  6. SQLserver Delete from where 与Oracle delete from where 的差异

    1.SQLserver 版本: select @@version; Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64) Dec 28 2012 20 ...

  7. 全民wifi钓鱼来临----agnes安卓wifi钓鱼神器介绍

    断断续续搞了一些无线的东西,从bt5的aircrack-ng的破无线(没怎么成功过)其实EWSA这个用GPU跑还算不错,可惜了我这显卡也只能每秒2500,到用c118在OsmocomBB基础上进行gs ...

  8. WPF与DevExpress之旅-序言

    随着.NET技术的发展,从之前的WINFORM转向到WPF是我们技术改革的必然趋势.WPF能给人带来震撼的视觉体验,也能更加规范我们的开发模式,与传统的WINFORM开发来说具有革命性的意义.DevE ...

  9. Java集合的小抄

    在尽可能短的篇幅里,将所有集合与并发集合的特征.实现方式.性能捋一遍.适合所有"精通Java",其实还不那么自信的人阅读. [转自:花钱的年华] 期望能不止用于面试时,平时选择数据 ...

  10. Windows Phone中的几种集合控件

    前言 Windows Phone开发过程中不可避免的就是和集合数据打交道,如果之前做过WP App的开发的话,相信你已经看过了各种集合控件的使用.扩展和自定义.这些个内容在这篇博客里都没有,那么我们今 ...