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& ...
随机推荐
- Nginx源码完全注释(5)core/ngx_cpuinfo.c
/* * Copyright (C) Igor Sysoev * Copyright (C) Nginx, Inc. */ #include <ngx_config.h> #include ...
- linux系统文件属性详解
一.文件信息 当创建一个文件的时候,系统保存了有关该文件的全部信息,包括: 文件的位置: 文件类型: 文件长度: 哪位用户拥有该文件,哪些用户可以访问该文件: 硬连接计数: 文件的修改时间: 文件的权 ...
- STL中mem_fun, mem_fun_ref用法
1.引言 先看一个STL中for_each的用法: #include <iostream> #include <vector> #include <algorithm&g ...
- Win 7 Windows Update无法自动更新解决方案
最近发现系统很长时间没有自动更新过了,手动更新后,提示返回错误码WindowsUpdate_8024402F.网络上搜索到的解决方法大多是删除更新临时目录,重启WINDOWS UPDATE服务,然而试 ...
- Mybatis:动态sql
动态 SQL MyBatis 的强大特性之一便是它的动态 SQL.如果你有使用 JDBC 或其他类似框架的经验,你就能体会到根据不同条件拼接 SQL 语句有多么痛苦.拼接的时候要确保不能忘了必要的空格 ...
- 实践作业4---DAY4阶段三。
阶段三:给出结论 这一阶段,我们首先列表从核心功能.细节.用户体验.辅助功能差异化功能.软件的适应性和成长性展开.我们得结论前参考了权威网站数据.并自己也做了相应分析. 结论:经过这么多工作,这个软件 ...
- 01 A Counting DNA Nucleotides
Problem A string is simply an ordered collection of symbols selected from some alphabet and formed i ...
- PLSA算法(转)
文章分类:综合技术 1. 引子 Bag-of-Words 模型是NLP和IR领域中的一个基本假设.在这个模型中,一个文档(document)被表示为一组单词(word/term)的无序组合,而忽略了语 ...
- 有一个5ml 的瓶子 和3ml 的瓶子 和 很多水 现在 要取出4ml的水 请写出编程 多种解法
//TODO public class demo { public static void main(String[] args) { demo.ss(); demo.sss(); } public ...
- WCF和ASP.NET Web API在应用上的选择(转)
出处:http://www.cnblogs.com/shanyou/archive/2012/09/26/2704814.html 在最近发布的Visual Studio 2012及.NET 4.5中 ...