Exporting array to Lua

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Exporting array to Lua

Nicholas Mario Wardhana
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?) 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.

Regards,
Nicholas Mario Wardhana



//=====================snippet
//
struct FragmentEdge
{
        // ...
};

struct Fragment
{
        FragmentEdge e[4];
};

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)) ,

//
//=====================

//===================== error message
//

1>------ Build started: Project: GameFactoryDemo, Configuration: Debug
Win32 ------
1>Compiling...
1>ScriptEngine.cpp
1>d:\nixx\project\gfa_work\gamefactorydemo\references\luabind\luabind\detail\call.hpp(354)
: error C2664: 'luabind::detail::raw_converter::apply' : cannot
convert parameter 2 from 'luabind::detail::by_const_reference<T>' to
'luabind::detail::by_pointer<T>'
1>        with
1>        [
1>            T=luabind::adl::object
1>        ]
1>        and
1>        [
1>            T=lua_State
1>        ]
1>        No user-defined-conversion operator available that can
perform this conversion, or the operator cannot be called
1>        d:\nixx\project\gfa_work\gamefactorydemo\references\luabind\luabind\detail\call.hpp(386)
: see reference to function template instantiation 'int
luabind::detail::returns<void>::call<WrappedClass,Policies,A0,A1>(void
(__cdecl *)(A0,A1),WrappedClass *,lua_State *,const Policies *)' being
compiled
1>        with
1>        [
1>            WrappedClass=GameFactory::C2Template::Fragment,
1>            Policies=luabind::detail::policy_cons<luabind::detail::raw_policy<2>,luabind::detail::null_type>,
1>            A0=GameFactory::C2Template::Fragment *,
1>            A1=const luabind::adl::object &
1>        ]
1>        d:\nixx\project\gfa_work\gamefactorydemo\references\luabind\luabind\class.hpp(210)
: see reference to function template instantiation 'int
luabind::detail::call<Class,Policies,void,GameFactory::C2Template::Fragment*,const
luabind::adl::object&>(R (__cdecl *)(A0,A1),WrappedClass *,lua_State
*,const Policies *)' being compiled
1>        with
1>        [
1>            Class=GameFactory::C2Template::Fragment,
1>            Policies=luabind::detail::policy_cons<luabind::detail::raw_policy<2>,luabind::detail::null_type>,
1>            R=void,
1>            A0=GameFactory::C2Template::Fragment *,
1>            A1=const luabind::adl::object &,
1>            WrappedClass=GameFactory::C2Template::Fragment
1>        ]
1>        d:\nixx\project\gfa_work\gamefactorydemo\references\luabind\luabind\class.hpp(209)
: while compiling class template member function 'int
luabind::detail::mem_fn_callback<Fn,Class,Policies>::operator
()(lua_State *) const'
1>        with
1>        [
1>            Fn=void (__cdecl *)(GameFactory::C2Template::Fragment
*,const luabind::adl::object &),
1>            Class=GameFactory::C2Template::Fragment,
1>            Policies=luabind::detail::policy_cons<luabind::detail::raw_policy<2>,luabind::detail::null_type>
1>        ]
1>        d:\nixx\project\gfa_work\gamefactorydemo\references\luabind\luabind\class.hpp(1520)
: see reference to class template instantiation
'luabind::detail::mem_fn_callback<Fn,Class,Policies>' being compiled
1>        with
1>        [
1>            Fn=void (__cdecl *)(GameFactory::C2Template::Fragment
*,const luabind::adl::object &),
1>            Class=GameFactory::C2Template::Fragment,
1>            Policies=luabind::detail::policy_cons<luabind::detail::raw_policy<2>,luabind::detail::null_type>
1>        ]
1>        d:\nixx\project\gfa_work\gamefactorydemo\references\luabind\luabind\class.hpp(1119)
: see reference to function template instantiation 'luabind::class_<T>
&luabind::class_<T>::virtual_def<luabind::adl::object(__cdecl
*)(GameFactory::C2Template::Fragment *,lua_State *),void(__cdecl
*)(GameFactory::C2Template::Fragment *,const luabind::adl::object
&),Policies>(const char *,const F &,const Default &,const Policies
&,boost::mpl::false_)' being compiled
1>        with
1>        [
1>            T=GameFactory::C2Template::Fragment,
1>            Policies=luabind::detail::policy_cons<luabind::detail::raw_policy<2>,luabind::detail::null_type>,
1>            F=luabind::adl::object (__cdecl
*)(GameFactory::C2Template::Fragment *,lua_State *),
1>            Default=void (__cdecl
*)(GameFactory::C2Template::Fragment *,const luabind::adl::object &)
1>        ]
1>        d:\nixx\project\gfa_work\gamefactorydemo\gamefactory\scriptengine.cpp(1224)
: see reference to function template instantiation 'luabind::class_<T>
&luabind::class_<T>::def<luabind::adl::object(__cdecl
*)(GameFactory::C2Template::Fragment *,lua_State *),void(__cdecl
*)(GameFactory::C2Template::Fragment *,const luabind::adl::object
&),luabind::detail::policy_cons<H,luabind::detail::null_type>>(const
char *,F,Default,const Policies &)' being compiled
1>        with
1>        [
1>            T=GameFactory::C2Template::Fragment,
1>            H=luabind::detail::raw_policy<2>,
1>            F=luabind::adl::object (__cdecl
*)(GameFactory::C2Template::Fragment *,lua_State *),
1>            Default=void (__cdecl
*)(GameFactory::C2Template::Fragment *,const luabind::adl::object &),
1>            Policies=luabind::detail::policy_cons<luabind::detail::raw_policy<2>,luabind::detail::null_type>
1>        ]
1>d:\nixx\project\gfa_work\gamefactorydemo\references\luabind\luabind\detail\call.hpp(364)
: error C2664: 'luabind::detail::raw_converter::converter_postcall' :
cannot convert parameter 2 from
'luabind::detail::by_const_reference<T>' to
'luabind::detail::by_pointer<T>'
1>        with
1>        [
1>            T=luabind::adl::object
1>        ]
1>        and
1>        [
1>            T=lua_State
1>        ]
1>        No user-defined-conversion operator available that can
perform this conversion, or the operator cannot be called
1>Build log was saved at
"file://d:\nixx\Project\GFA_Work\GameFactoryDemo\Debug\BuildLog.htm"
1>GameFactoryDemo - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

//
//=====================

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit.  See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Exporting array to Lua

Daniel Wallin
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
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user