c++返回多个表,如何知道返回表的名称
Return multiple tables to C++, how to know the returned table name
我使用Lua来实现一些函数,结果放在表s中并返回到c++代码。例如,在Lua的末尾,我将这些表返回给c++
return names, ages, courses
现在在c++中,我需要读取返回表中的元素。我怎样才能知道表的名称,从而知道要检索哪些元素?换句话说,下面的sudo代码说明了我想要做的事情:
if table_name == "names": //some commands can realize this?
lua_getfield(L, -1, "Tom");
the_name = lua_tostring(L, -1);
cout << the_name << endl;
Lua_pop(L, 1);
elif table_name == "ages": //similar to last comment...
lua_getfield(L, -1, "girls");
the_age = lua_tostring(L, -1);
....... //some operations
有人知道吗?顺便说一句,我在win7上使用Lua5.3.1
您将不知道先前存储表的变量名,但是您的Lua函数将以特定的顺序返回它们。在c++中,这些表是放在堆栈上的,所以courses
是上一个值,ages
是下一个值。
您可以在所有表中设置一个字段,其中包含它们的名称/类型
相关文章:
- 有人知道为什么在开关中使用stoi函数会返回恒定的错误吗
- 返回给定 SEXP 的子集,而无需知道实际的内部数据类型
- 创建一个始终返回零但优化器不知道的函数
- 当我使用按引用返回时,我不知道这些代码之间的区别
- 如何知道 sqlite 中的函数"回调"是否返回了一些东西?
- 任何人都知道如何解决尝试将从MySQL数据库返回的行打印到文本文件(.txt)中的C++
- 我的bool函数一直返回true,我不知道为什么
- rename()返回-1.如何知道重命名失败的原因
- C++ SQLite3 如何知道是否选择返回 0 行
- 如果向量包含重复项,则此函数应返回 true。知道为什么它不起作用吗?
- 如何使用 dlsym() 调用函数,如果我不知道返回类型和参数
- 不知道如何从气泡排序函数返回值
- 函数的调用方如何知道是否使用了返回值优化
- C++,我不知道为什么我的函数不返回结果
- 我的返回语句有一个错误,我不知道要修复
- c++返回多个表,如何知道返回表的名称
- 当返回一个集合指针时,客户端如何知道它是否需要销毁它?
- 不知道为什么我的函数一直返回相同的值
- 编译器如何知道函数调用后控制应该返回到哪里?
- python脚本能知道C++主函数在Android环境中的返回值吗