c 调用 lua 向lua函数 传递table
参考 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的更多相关文章
- C调用Lua中的函数解析table
Passing Tables to Lua Functions A use case that happens often is the passing of tables to and from L ...
- lua的克隆函数,table的深度拷贝
--深度拷贝Table function DeepCopy(obj) local InTable = {}; local function Func(obj) if type(obj) ~= &quo ...
- (原)lua使用ffi调用c程序的函数
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5812763.html 参考网址: http://luajit.freelists.narkive.co ...
- lua调用dll导出的函数
参考手册 hello.dll #include "pch.h" #include "lua.hpp" #pragma comment(lib, "lu ...
- Lua学习(4)——函数
在Lua中函数的调用方式和C语言基本相同,如:print("Hello World")和a = add(x, y).唯一的差别是,如果函数只有一个参数,并且该参数的类型为字符串常量 ...
- Lua中的函数
[前言] Lua中的函数和C++中的函数的含义是一致的,Lua中的函数格式如下: function MyFunc(param) -- Do something end 在调用函数时,也需要将对应的参数 ...
- lua加载函数require和dofile
lua加载函数require和dofile Lua提供高级的require函数来加载运行库.粗略的说require和dofile完成同样的功能但有两点不同: 1. require会搜索目录加载文件; ...
- lua学习之函数篇
函数 函数是对语句和表达式进行抽象的主要机制 两种用法 一是可以完成特定的任务,一句函数调用被视为一条语句 二是以只用来计算并返回特定的结果,视为一句表达式 print("Hello, Wo ...
- [lua]紫猫lua教程-命令宝典-L1-01-07. table表
L1[table]01. table表的定义与赋值 小知识:声明表的例子 xx={}--创建一个空表xx --给这表的元素赋值 test="a" xx[test]="a& ...
随机推荐
- 135. Candy(Array; Greedy)
There are N children standing in a line. Each child is assigned a rating value. You are giving candi ...
- spring4-1-Spring的简单介绍
Spring4.0 是 Spring 推出的一个重大版本升级,进一步加强了 Sring 作为 Java 领域第一开源平台的地位.Spring4.0 引入了众多 Java 开发者期盼的新特性,如泛型依赖 ...
- Openssl rand命令
一.简介 rand命令用来产生伪随机字节,随机数字产生器需要一个seed,在没有/dev/srandom系统下的解决方法是自己做一个~/.rnd文件 二.语法 openssl rand [-out f ...
- [Training Video - 3] [Groovy in Detail] Non-static and Static variables, objects and object referances
log.info "starting" // we use class to create objects of a class Planet p1 = new Planet() ...
- JMS 之 Active MQ 的消息传输
本文使用Active MQ5.6 一.消息协商器(Message Broker) broke:消息的交换器,就是对消息进行管理的容器.ActiveMQ 可以创建多个 Broker,客户端与Active ...
- loadlibrary 文档
http://www.pinvoke.net/default.aspx/kernel32.LoadLibrary LIBRARY ModelBank EXPORTS CND;GBlackScholes ...
- HDU 2159 FATE (二维背包)
题意:中文题. 析:dp[i][j] 已经杀了 i 个怪兽,已经用了 j 体积,所能获得的最大经验值,这个和一维的差不多,只是加一维而已. 代码如下: #pragma comment(linker, ...
- HDU 1104 Remainder (BFS求最小步数 打印路径)
题目链接 题意 : 给你N,K,M,N可以+,- ,*,% M,然后变为新的N,问你最少几次操作能使(原来的N+1)%K与(新的N)%k相等.并输出相应的操作. 思路 : 首先要注意题中给的%,是要将 ...
- zookeeper学习及安装
HBase提示已创建表,但是list查询时,却显示表不存在. https://blog.csdn.net/liu16659/article/details/80216085 http://archiv ...
- 谷歌浏览器插件开发入门-官方版Helloworld详解
目录: 需求 原理 实现步骤: 一个空的插件 一个可以设置一种背景色的插件(可以设置百度首页的背景色为绿色) 一个可以设置多种背景色的插件 需求: 插件可以改变特定网址的背景颜色. 原理: 将各种ht ...