[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] LuaClassBasedCall 1.0
- From: Александр Мельников <a.melnikov69@...>
- Date: Sun, 24 Apr 2011 17:15:48 +0700
Hello Patrick,
I found small bug, in lgencall.hpp.
In:
template<class T> inline void Output::GetVector(lua_State* L, int idx) const
{
vector<T>* v = (vector<T>*)PointerValue;
luaL_checktype(L, idx, LUA_TTABLE);
size_t len = lua_objlen(L, idx);
int top = lua_gettop(L);
for(size_t i=0;i<len;i++)
{
lua_pushinteger(L, i+1);
lua_gettable(L, idx);
T value;
Output output(value);
--- output.Get(L, -1);
+++ output.Get(L, idx+1);
v->push_back(value);
lua_settop(L, top);
}
}
It fix allow use std::vector< std::vector< T ....
Instead code throw an exception: Lua exception: attempt to index a number
value
My example works after this fix.
#include <iostream>
#define LCBC_USE_CSL 1
#include "lgencall.hpp"
using namespace lua;
typedef std::vector<std::vector<int> > vvs_type;
typedef std::vector<int> vs_type;
int main(int argc, char* argv[])
{
Lua L; // The constructor will open a new Lua state and include
libraries
try
{
vvs_type vvs;
L.ExceptCall("mytable = {{1,2},{3,4},{5,6}}; return mytable",
Outputs(Output(vvs)));
for(vvs_type::const_iterator oit=vvs.begin();
oit!=vvs.end();
++oit)
{
for(vs_type::const_iterator it=(*oit).begin();
it!=(*oit).end();
++it)
std::cout << *it << " ";
std::cout << std::endl;
}
vs_type vs;
L.ExceptCall("mytable = {10,20,30,40,50,60}; return mytable",
Outputs(Output(vs)));
for(vs_type::const_iterator it=vs.begin();
it!=vs.end();
++it)
std::cout << *it << " ";
std::cout << std::endl;
}
catch(Error err)
{
printf("Lua exception: %s\n", (const char*)err);
}
} // The Lua state is closed by the destructor
Alexander.