参考 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. Ros学习——Cmakelists.txt文件解读

    1.过程 .Required CMake Version (cmake_minimum_required) //CMake 需要的版本 .Package Name (project()) //#定义工 ...

  2. mysql5.6配置semi_sync

    测试环境:Red Hat Enterprise Linux Server release 6.3 (Santiago)Server version: 5.6.22-log MySQL Communit ...

  3. java中的不死兔问题(斐波那契数列)(递归思想)

    有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? public class Item { public static ...

  4. [C++] Pure Virtual Function and Abstract Class

    Pure Virtual Function Abstract Class

  5. ethtool -p eth0 物理口一个灯在不停的闪烁

    摘自:https://blog.csdn.net/morigejile/article/details/78598645 你的  服务器有多个网卡并且已经配置好运行当中,你却没记得eth0.eth1. ...

  6. sql查询层级分类

    先上个效果图吧 CTE递归查询里面用了一些小的技巧,查询出结果以后在前端用表格展示出来,层级视觉效果还是很明显的 with tree as(select [ID],[Name],[Address],[ ...

  7. javascript总结41:表格全选反选,经典案例详解

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  8. javascript总结19:javascript 使用概述

    1 JS作用 1.验证表单(以前的网速慢)`` 2.页面特效(PC端的网页效果) 3.移动端(移动web和app) 4.异步和服务器交互(AJAX) 5.服务端开发(nodejs) 2 浏览器的主要构 ...

  9. CodeForces 289B Polo the Penguin and Matrix (数学,中位数)

    题意:给定 n * m 个数,然后每次只能把其中一个数减少d, 问你能不能最后所有的数相等. 析:很简单么,首先这个矩阵没什么用,用一维的存,然后找那个中位数即可,如果所有的数减去中位数,都能整除d, ...

  10. set集合排序

    不仅list是有序集合,set也可以变为有序集合. /** * 给字符串时间的set排序 * @return 有序的set集合 */ public static Set getSort(){ Set& ...