传Lua对象到Cpp
传Lua对象到Cpp
(金庆的专栏)
摘自:http://raycast.net/lua-intf
以下代码演示了Lua函数和表传入Cpp进行处理:
std::string acceptStuff(LuaRef luaObj,
const std::vector<std::string>& stringVector,
std::map<std::string, int>& dict)
{
// Assume that this function expects Lua object (table) as first argument
auto func = luaObj.get<std::function<std::string(int)>>("func");
auto stringField = luaObj.get<std::string>("str");
std::ostringstream s;
s << "func() result: " << func(10) << ", string field value: " << stringField << "\n";
s << "Vector size: " << stringVector.size() << ", first element: " << stringVector[0] << "\n";
s << "Dictionary size: " << dict.size() << ", first element: (" <<
dict.begin()->first << ", " << dict.begin()->second << ")";
return s.str();
}
LuaBinding(lua).beginModule("test")
.addFunction("acceptStuff", &acceptStuff)
.endModule();
// Lua
local obj = {
func = function(i)
return "You passed number " .. i
end,
str = "Hello, world"
}
local v = { 1, 2, 3 }
local dict = { first = 1, second = 2 }
print(test.acceptStuff(obj, v, dict))
// Output
func() result: You passed number 10, string field value: Hello, world
Vector size: 3, first element: 1
Dictionary size: 2, first element: (first, 1)
传Lua对象到Cpp的更多相关文章
- intent传值传对象跳转
intent传值传对象跳转 1.传值 //原activity中存入一个字段 intent = new Intent(From.this, To.class); intent.putExtra(&quo ...
- @requestbody---接受前端传json对象并绑定javabean
@requestbody---接受前端传json对象并绑定javabean----https://blog.csdn.net/ljxbbss/article/details/74452326 最近代码 ...
- xlua中lua对象到c#对象的转型
lua中的类型 基础类型 #define LUA_TNIL 0 #define LUA_TBOOLEAN 1 #define LUA_TLIGHTUSERDATA 2 #define LUA_TNUM ...
- IDEA同步上传lua代码,方便开发。
因项目是Java和lua一起开发的,以前用Notepad++插件连接,每次关掉得重新寻找目录.有点耗时间,所以用idea提供的工具很是便利,再此做个笔记. 点击上面的绿色”+“号,添加 在配置mapp ...
- PHP关于传众多参数还是传上下文对象的性能测试
在开发微信公众平台平台的过程中,有这么几个参数总是需要传来传去,$userOpenId,$message,$time. 在整个程序的运行过程中,为了函数方便的处理,将这三个变量一直放在参数列表里.关于 ...
- JQuery Ajax 使用FormData上传文件对象
FormData部分: 先new FormData对象 :let somedata = new FormData(),然后将数据添加进去,这里我们使用append()进行添加. 这里举一个上传头像的例 ...
- JAVA之等号、传类对象参数与c++的区别
在JAVA中用等号对类对象进行赋值,实际上操作的是对象的地址. eg: package MyText; class ClassA { int value; public void seta(int v ...
- vue给input file绑定函数获取当前上传的对象
HTML <input type="file" @change="tirggerFile($event)"> JS(vue-methods) tir ...
- LUA对象
Rectangle = {width = , height = , area = }; function Rectangle:new(o, width, height) o = o or {}; se ...
随机推荐
- [LeetCode] Bulb Switcher II 灯泡开关之二
There is a room with n lights which are turned on initially and 4 buttons on the wall. After perform ...
- 原生JS面向对象方法实现万年历
###面向对象的方法实现万年历 实现思路: 1.创建构造函数constructor ``` function Calender(main){ this.current ...
- Redis数据类型--string
在Redis中支持丰富的数据类型的存储系统,包括:字符串(string),散列(hashes),列表(lists),集合(sets),有序集合(sorted sets),与范围查询,bitmaps,h ...
- ActiveMQ笔记:一个高稳定,可扩展的的部署方案
本文介绍一个笔者在实际工作中的实施的基于ActiveMQ的一个高稳定,可扩展的异步消息系统. ActiveMQ是一个成熟的基于Java语言的开源消息系统,在实际应用中被大量使用.ActiveMQ在系统 ...
- [Codeforces 864F]Cities Excursions
Description There are n cities in Berland. Some pairs of them are connected with m directed roads. O ...
- ●POJ 2794 Double Patience
题链: http://poj.org/problem?id=2794题解: 状压DP,概率 9元组表示每一堆还剩几张牌.可以用5进制状压,共5^9=1953124个状态. 令P(S)表示S这个状态被取 ...
- 【USACO】干草金字塔
题目描述 贝西要用干草包堆出一座金字塔.干草包会从传送带上陆续运来,依次出现 N 包,每包干草可 以看做是一个二维平面上的一个长方形,第 i 包干草的宽度是 W i ,长度统一为 1. 金字塔的修建有 ...
- hdu 5011(博弈)
题意:在许多堆石子中,两人轮流取,1.在一堆中取至少一个 2.将这一堆分成两堆 思路:NIM游戏,所有值的异或,当其为0时失败 nim游戏: 假设只有两堆,游戏人取得胜利并不在于N1和N2的值具体是 ...
- [51nod1239欧拉函数之和]
来自FallDream的博客,未经允许,请勿转载,谢谢 --------------------------------------------- 给定n,求$S(n)=\sum_{i=1}^{n}\ ...
- Delphi7 ADO面板上的控件简介
? ADO Connection的主要方法:1) Begin Trans 开始启动一个新的事务,必须保证数据连接处于激活状态.2) Cancel 关闭于数据库的连接.3) Commit T ...