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& ...
随机推荐
- 使用zTree展开节点后,覆盖了下一个节点
如图所示,结果是zTree与<fieldset>标签不兼容....我去!!! 也就是说Ztree不能放在<fieldset>标签中..
- porwedesigner 去掉引号
PowerDesigner生成的ORACLE 建表脚本中去掉对象的双引号,设置大.小写 若要将 CDM 中将 Entity的标识符都设为指定的大小写,则可以这么设定: 打开cdm的情况下,进入Tool ...
- SQLSERVER Tempdb的作用及优化
tempdb 系统数据库是可供连接到 SQL Server 实例的所有用户使用的全局资源.tempdb 数据库用于存储下列对象:用户对象.内部对象和版本存储区. 用户对象 用户对象由用户显式创建.这些 ...
- Cocos2dx之touch事件
今天看了下ccocos2dx touch事件部分的源码,从CCTouch.CCTouchHandler和CCTouchDispatcher简单的做了分析和总结,先直接看源码吧! 1.CCTouch c ...
- No member named 'setResizeMode' in 'QHeaderView' - Convert Qt 4.7 to Qt 5.8
https://stackoverflow.com/questions/42743141/no-member-named-setresizemode-in-qheaderview-convert-qt ...
- gradle创建spring-boot项目
刚来新公司,熟悉了公司项目搭建的框架,了解到了一种新的项目管理工具:gradle,从网上了解,据说比maven更加灵活化,于是便学习了一番.在此记录下来,一遍以后使用.gradle的安装就不说了,网上 ...
- RF和GBDT的区别
Random Forest 采用bagging思想,即利用bootstrap抽样,得到若干个数据集,每个数据集都训练一颗树. 构建决策树时,每次分类节点时,并不是考虑全部特征,而是从特征候选集中选取 ...
- vCenter Server Heartbeat
1.简介 vCenter Server Heartbeat为VMware vCenter Server提供关键任务高可用性,保护虚拟基础架构免受硬件.网络.配置等的影响,基于Windows的服务,可为 ...
- [Lua快速了解一下]Lua的函数
-recurrsive function fib(n) end ) + fib(n - ) end -closure 示例一 function newCounter() return function ...
- Java中的Type
Type是Java 编程语言中所有类型的公共高级接口(官方解释),也就是Java中所有类型的“爹”:其中,“所有类型”的描述尤为值得关注.它并不是我们平常工作中经常使用的 int.String.Lis ...