BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / soft-design / #43052同步于 2013/1/30
该镜像源已超过 30 天没有更新,可能在源站已被删除。
SoftDesign机器人发帖

[请教]使用luabind封装std::vector的问题

Xer
2013/1/30镜像同步3 回复
rt,想使用luabind封装std::vector的at函数: [code] #include <lua.hpp> #include <luabind.hpp> #include <luabind/return_reference_to_policy.hpp> #include <iostream> #include <vector> #include <string> using namespace std; int main() { lua_State *myLuaState = luaL_newstate(); luaL_openlibs(myLuaState); luabind::open(myLuaState); luabind::module(myLuaState) [ luabind::class_<vector<int> >("myvec") .def(luabind::constructor<>()) .def("push_back", &vector<int>::push_back) .def("size", &vector<int>::size) .def("at", (int& (vector<int>::*)(unsigned int))&vector<int>::at, luabind::return_reference_to(_1)) ]; if (luaL_dofile(myLuaState, "test.lua") != 0) cout << "dofile error -> " << lua_tostring(myLuaState, -1) << endl; lua_close(myLuaState); getchar(); return 0; } [/code] 用到的lua脚本test.lua如下: [code] v = myvec() v.push_back(v, 10) print(v:size()) print(v:at(0)) [/code] 编译通过,运行的时候出现错误提示: dofile error -> No such operator defined 网上搜了下没找到有用的信息,请问一下这个问题怎样解决?
订阅后,新回复会通过你的通知中心匿名送达。
3 条回复
tonyjansan机器人#1 · 2013/1/30
阿诺...脚本里的那个v.push_back(v, 10)是啥情况? void vector::push_back ( const T& x ); 【 在 Xer 的大作中提到: 】 : rt,想使用luabind封装std::vector的at函数: : [code] : #include <lua.hpp> : ...................
Xer机器人#2 · 2013/1/30
push_back没重载,因此不用指定函数签名,另外在c++中执行v.push_back(10)也是没有问题的 【 在 tonyjansan (FOR THOSE WHO DO.) 的大作中提到: 】 : 阿诺...脚本里的那个v.push_back(v, 10)是啥情况? : void vector::push_back ( const T& x );
tonyjansan机器人#3 · 2013/1/31
不是重载不重载的问题~我是想说既然你都知道在C++里是v.push_back(10),那为什么写脚本的时候要写成v.push_back(v, 10)? 要不然就是lua_pushnumber(v, 10),要不然就是v.push_back(10)吧?... 【 在 Xer 的大作中提到: 】 : push_back没重载,因此不用指定函数签名,另外在c++中执行v.push_back(10)也是没有问题的 :