Re: Exporting array to Lua
Daniel Wallin <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
On Wed, Jun 23, 2010 at 10:48:13PM +0800, Nicholas Mario Wardhana wrote:
> Hi all,
>
> I have a problem in exporting an array member of a struct to Lua
> (snippet in footnote). I noticed that currently Lua cannot do this, so
> I searched and found this:
>
> http://old.nabble.com/how-to-bind-a-raw-array--td21440448.html
>
> It lists the wrapper methods to convert the Lua table into the
> corresponding array. However, it uses luabind::argument, which is not
> found (deprecated feature?)
No, it's in 0.9.
> so I change it to object and the methods can compile. Now, if I use
> the get function, the program can compile, but it can't if I also pass
> the set function. I include the error message below. So, did I do
> something wrong here? Any help on this issue is appreciated. Thank you
> very much.
> luabind::object get_data_Fragment_e(Fragment* const f, lua_State* L)
> {
> luabind::object result = luabind::newtable(L);
>
> for (int i = 0; i < 4; ++i)
> result[i + 1] = f->e[i];
>
> return result;
> }
>
> void set_data_Fragment_e(Fragment* const f, luabind::object const& table)
> {
> for (int i = 0; i < 4; ++i)
> f->e[i] = luabind::object_cast<FragmentEdge>(table[i + 1]);
> }
>
> // export function
> class_<Fragment>("_Fragment")
> .def("e", get_data_Fragment_e, set_data_Fragment_e, raw(_2)) ,
^^^^
This should be "property()". That's the only error I can find. I
recommend you update to 0.9 which should be considerably better than the
version you are using now. Among more important things, 0.9 has
deprecated raw(), handling lua_State* arguments automatically.
--
Daniel Wallin
BoostPro Computing
http://www.boostpro.com
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first