参考 https://www.myvoipapp.com/blogs/yxh/2016/07/14/c%E5%90%91lua%E5%87%BD%E6%95%B0%E4%BC%A0%E9%80%92table%E5%8F%82%E6%95%B0/

1.lua

function showstr(str2)
print("The string you input is " .. str2.name)
end

1.c

 gcc -o 1 1.c  -llua-5.1
#include <stdio.h>  

//lua头文件
#ifdef __cplusplus
extern "C" {
#include "lua.h"
#include <lauxlib.h>
#include <lualib.h>
}
#else
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#endif /*
lua -> c
https://www.cnblogs.com/coderkian/p/4057750.html https://www.cnblogs.com/pied/archive/2012/10/26/2741601.html
gcc -o lua lua.c -llua-5.1 https://www.cnblogs.com/sevenyuan/p/4511808.html
*/ int main(int argc,char ** argv)
{ lua_State * L=NULL; /* 初始化 Lua */
L = lua_open(); /* 载入Lua基本库 */
luaL_openlibs(L); /* 运行脚本 */
int error = luaL_dofile(L, "./1.lua");
if(error) {
perror("luaL_dofile error");
return ;
} lua_getglobal(L,"showstr");
lua_newtable(L); // 创建一个table
lua_pushstring(L, "name"); //key为intVal
lua_pushinteger(L,); //值为1234
lua_settable(L, -); //写入table lua_pcall(L,,,); /* 清除Lua */
lua_close(L); return ;
}

c 调用 lua 向lua函数 传递table的更多相关文章

  1. C调用Lua中的函数解析table

    Passing Tables to Lua Functions A use case that happens often is the passing of tables to and from L ...

  2. lua的克隆函数,table的深度拷贝

    --深度拷贝Table function DeepCopy(obj) local InTable = {}; local function Func(obj) if type(obj) ~= &quo ...

  3. (原)lua使用ffi调用c程序的函数

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5812763.html 参考网址: http://luajit.freelists.narkive.co ...

  4. lua调用dll导出的函数

    参考手册 hello.dll #include "pch.h" #include "lua.hpp" #pragma comment(lib, "lu ...

  5. Lua学习(4)——函数

    在Lua中函数的调用方式和C语言基本相同,如:print("Hello World")和a = add(x, y).唯一的差别是,如果函数只有一个参数,并且该参数的类型为字符串常量 ...

  6. Lua中的函数

    [前言] Lua中的函数和C++中的函数的含义是一致的,Lua中的函数格式如下: function MyFunc(param) -- Do something end 在调用函数时,也需要将对应的参数 ...

  7. lua加载函数require和dofile

    lua加载函数require和dofile Lua提供高级的require函数来加载运行库.粗略的说require和dofile完成同样的功能但有两点不同: 1. require会搜索目录加载文件; ...

  8. lua学习之函数篇

    函数 函数是对语句和表达式进行抽象的主要机制 两种用法 一是可以完成特定的任务,一句函数调用被视为一条语句 二是以只用来计算并返回特定的结果,视为一句表达式 print("Hello, Wo ...

  9. [lua]紫猫lua教程-命令宝典-L1-01-07. table表

    L1[table]01. table表的定义与赋值 小知识:声明表的例子 xx={}--创建一个空表xx --给这表的元素赋值 test="a" xx[test]="a& ...

随机推荐

  1. Opencv 发现轮廓 findContours

    vector<vector<Point>> vec_p; vector<Vec4i> vec_4f; findContours(img_canny1, vec_p, ...

  2. qy Undefied index报错

    目测是不支持如下写法 $value['status'] = $map[$value['status']];

  3. [BAT] 通过批处理加host

    echo. >> %WINDIR%\system32\drivers\etc\hosts & echo xxx.xxx.xxx.xx test_host >> %WIN ...

  4. javascript和jquery比较

    <h1>我的第一段 JavaScript</h1> <p>请输入数字.如果输入值不是数字,浏览器会弹出提示框.</p> <input id=&qu ...

  5. 【转载】mysql中timestamp,datetime,int类型的区别与优劣

    转载来自souldak,微博:@evagle以下内容整合筛选自互联网: int1. 占用4个字节2. 建立索引之后,查询速度快3. 条件范围搜索可以使用使用between4. 不能使用mysql提供的 ...

  6. CodeForces 347B Fixed Points (水题)

    题意:给定 n 数,让你交换最多1次,求满足 ai = i的元素个数. 析:很简单么,只要暴力一遍就OK了,先把符合的扫出来,然后再想,最多只能交换一次,也就是说最多也就是加两个,然后一个的判,注意数 ...

  7. (I/O流)在100ms内桌面上生成一个200M大小的文件

    最终速度取决于硬盘的读写速度 package com.laurdawn; import java.io.File; import java.io.FileInputStream; import jav ...

  8. URAL 1698. Square Country 5(记忆化搜索)

    题目链接 题意 : 自守数的定义:如果某个数的平方的末尾几位数等于这个数,那么就称这个数为自守数.例如5*5=25,则5就是自守数.让你求不超过n位的自守数有多少 思路 : 实际上,自守数还有两个性质 ...

  9. STS 闪退

    # # A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ILLEGAL_INSTRUCTI ...

  10. Unity NetWork

    using UnityEngine; using System.Collections; public class NetworkTest : MonoBehaviour { ;//端口号 strin ...