Uncertain about luabind

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

Uncertain about luabind

Tomas Cokis
Hey guys, I'm really new to luabind (just got it compiling) and looking through the documentation I'm a bit uncertain of how to do something.

Namely, how can I declare variables (in current, c++ scope) to luabind?

My goal here is to, in a constructor of an object load a lua file to initialise its variables.

I'm aware of how to declare classes and functions, however it doesn't seem like I can register an actual object or variables instance - the only solution I can think of it giving every variable its own get/set function, and add an additional layer - however isn't this what lua bind is supposed to do? Bind c++ to lua?
Reply | Threaded
Open this post in threaded view
|

Re: Uncertain about luabind

Daniel Wallin
Tomas Cokis wrote:
> Hey guys, I'm really new to luabind (just got it compiling) and looking
> through the documentation I'm a bit uncertain of how to do something.
>
> Namely, how can I declare variables (in current, c++ scope) to luabind?

You can expose values to lua using the API wrappers in luabind. For
instance:

  luabind::globals(L)["something"] = some_value;

Is that what you are looking for?

> My goal here is to, in a constructor of an object load a lua file to
> initialise its variables.
>
> I'm aware of how to declare classes and functions, however it doesn't seem
> like I can register an actual object or variables instance - the only
> solution I can think of it giving every variable its own get/set function,
> and add an additional layer - however isn't this what lua bind is supposed
> to do? Bind c++ to lua?

It's also possible to export public members using def_readwrite() and
def_readonly():

  class_<X>("X")
      .def_readwrite("value", &X::value)

You can not however export non-member variables as properties.

HTH,
--
Daniel Wallin
BoostPro Computing
http://www.boostpro.com

------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Uncertain about luabind

Tomas Cokis

Daniel Wallin-4 wrote
  luabind::globals(L)["something"] = some_value;
This looks like what I wanted, can you send values back into c++ through 'some_value'?

Also, come to think of it is there a way to load lua files through luabind or do I have to load it and then run it through luaL_dostring()?

Thanks for helping a newb
Reply | Threaded
Open this post in threaded view
|

Re: Uncertain about luabind

Tomas Cokis
I've just been mucking around with it, and while global can send variables into lua, it won't accept pointers and will not 'sync' itself with my c++ code. Is there any other way to do this?
Reply | Threaded
Open this post in threaded view
|

Re: Uncertain about luabind

Teto
In reply to this post by Tomas Cokis
On Thu, Jan 14, 2010 at 1:58 PM, Tomas Cokis <[hidden email]> wrote:

>
>
>
> Daniel Wallin-4 wrote:
>>
>>   luabind::globals(L)["something"] = some_value;
>>
>
> This looks like what I wanted, can you send values back into c++ through
> 'some_value'?
>
> Also, come to think of it is there a way to load lua files through luabind
> or do I have to load it and then run it through luaL_dostring()?

I do this personnaly, maybe there is a better way
    try {
        // run the script
        if (luaL_dofile(mLuaState,param.c_str()) != 0){
            // error
            fus::ILogger::Log(fus::EError) << lua_tostring(mLuaState,-1);
            return false;
        }
    }
    catch(luabind::error& e){
        fus::ILogger::Log(fus::EError) << lua_tostring(mLuaState,-1);
        return false;
    }

> Thanks for helping a newb
> --
> View this message in context: http://old.nabble.com/Uncertain-about-luabind-tp27160576p27160893.html
> Sent from the Lua C++ Bind mailing list archive at Nabble.com.
>
>
> ------------------------------------------------------------------------------
> Throughout its 18-year history, RSA Conference consistently attracts the
> world's best and brightest in the field, creating opportunities for Conference
> attendees to learn about information security's most important issues through
> interactions with peers, luminaries and emerging and established companies.
> http://p.sf.net/sfu/rsaconf-dev2dev
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>

------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Uncertain about luabind

Teto
In reply to this post by Tomas Cokis
On Thu, Jan 14, 2010 at 2:43 PM, Tomas Cokis <[hidden email]> wrote:
>
> I've just been mucking around with it, and while global can send variables
> into lua, it won't accept pointers and will not 'sync' itself with my c++
> code. Is there any other way to do this?

It perfeclty accept pointers for example:   global_vars["Level"] = this;


> --
> View this message in context: http://old.nabble.com/Uncertain-about-luabind-tp27160576p27161425.html
> Sent from the Lua C++ Bind mailing list archive at Nabble.com.
>
>
> ------------------------------------------------------------------------------
> Throughout its 18-year history, RSA Conference consistently attracts the
> world's best and brightest in the field, creating opportunities for Conference
> attendees to learn about information security's most important issues through
> interactions with peers, luminaries and emerging and established companies.
> http://p.sf.net/sfu/rsaconf-dev2dev
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>

------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Uncertain about luabind

Tomas Cokis

Teto-2 wrote
It perfeclty accept pointers for example:   global_vars["Level"] = this;
When I try this:

double c_x;

object global_vars = globals(m_LuaState);

global_vars["c_x"] = &c_x; // It SIGABRT's me here

while if I simply try:

global_vars["c_x"] = c_x;

it runs fine - so if its accepting pointer for you its not for me.

I have found a work around

globals(m_LuaState)["c_x"] = c_x; // For sending

c_x = luabind::object_cast<float>(luabind::globals(m_LuaState)["c_x"]); // For reading

If there is a way to do it with pointers though I would really like to know - having to run through a refresh list to sync really sucks.
Reply | Threaded
Open this post in threaded view
|

Re: Uncertain about luabind

T.bear
I think you have to put c_x in a structure to make it a reference. Lua number is always treated as a value.

On Thu, Jan 14, 2010 at 9:53 AM, Tomas Cokis <[hidden email]> wrote:



Teto-2 wrote:
>
>
> It perfeclty accept pointers for example:   global_vars["Level"] = this;
>
>

When I try this:

double c_x;

object global_vars = globals(m_LuaState);

global_vars["c_x"] = &c_x; // It SIGABRT's me here

while if I simply try:

global_vars["c_x"] = c_x;

it runs fine - so if its accepting pointer for you its not for me.

I have found a work around

globals(m_LuaState)["c_x"] = c_x; // For sending

c_x = luabind::object_cast<float>(luabind::globals(m_LuaState)["c_x"]); //
For reading

If there is a way to do it with pointers though I would really like to know
- having to run through a refresh list to sync really sucks.
--
View this message in context: http://old.nabble.com/Uncertain-about-luabind-tp27160576p27162485.html
Sent from the Lua C++ Bind mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Uncertain about luabind

Tomas Cokis

Taesoo Kwon wrote
I think you have to put c_x in a structure to make it a reference. Lua
number is always treated as a value.
I was hoping I wouldn't have to do something like that, but oh well.
Reply | Threaded
Open this post in threaded view
|

Re: Uncertain about luabind

Tomas Cokis
I'm afraid I'm still having some trouble, consider this:

struct nLuaVar
{
public:
       
        int* sender;
};

void Raster_Lua_SetupVar(lua_State* Slate)
{
        module(Slate)[
                                  class_<nLuaVar>("nLuaVar")
                                        .def_readwrite("sender", &nLuaVar::sender)
                            ];
}

void Raster_Lua_LoadVar(lua_State* Slate, const char* name, int* variable)
{
        nLuaVar newValue;
       
        newValue.sender = variable;
       
        globals(Slate)[name] = newValue;
       
}

This seems to be what should work -- A pointer in a structure registered in a lua module

However, when I go:

Raster_Lua_SetupVar(m_LuaState);

Raster_Lua_LoadVar(m_LuaState, "m_size", &m_size);

luaL_dofile (m_LuaState, filePath.c_str());

where the lua file is

-- Stuff

m_size.sender = 1

--More stuff

Luabind reports an error at that point, and anything after that point in the luafile does not get done.

Is there something I am doing wrong?
Reply | Threaded
Open this post in threaded view
|

Re: Uncertain about luabind

T.bear
I think you have two choices.
1.
struct nLuaVar
{
public:
int sender;
};
and send a pointer of nLuaVar instance to lua. In this case, you can use def_readwrite.

or 2.
define a setter and getter function, and use .property. (see luabind manual).
.property



On Thu, Jan 14, 2010 at 12:25 PM, Tomas Cokis <[hidden email]> wrote:

I'm afraid I'm still having some trouble, consider this:

struct nLuaVar
{
public:

       int* sender;
};

void Raster_Lua_SetupVar(lua_State* Slate)
{
       module(Slate)[
                                 class_<nLuaVar>("nLuaVar")
                                       .def_readwrite("sender", &nLuaVar::sender)
                           ];
}

void Raster_Lua_LoadVar(lua_State* Slate, const char* name, int* variable)
{
       nLuaVar newValue;

       newValue.sender = variable;

       globals(Slate)[name] = newValue;

}

This seems to be what should work -- A pointer in a structure registered in
a lua module

However, when I go:

Raster_Lua_SetupVar(m_LuaState);

Raster_Lua_LoadVar(m_LuaState, "m_size", &m_size);

luaL_dofile (m_LuaState, filePath.c_str());

where the lua file is

-- Stuff

m_size.sender = 1

--More stuff

Luabind reports an error at that point, and anything after that point in the
luafile does not get done.

Is there something I am doing wrong?
--
View this message in context: http://old.nabble.com/Uncertain-about-luabind-tp27160576p27164964.html
Sent from the Lua C++ Bind mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Uncertain about luabind

Tomas Cokis
It won't even let me pass classes as a pointer - I think there must be something wrong with my build. Sigh.

Does anyone know if theres a binary (Mac) I can find somewhere?
Reply | Threaded
Open this post in threaded view
|

Re: Uncertain about luabind

Schala Zeal
I suggest getting Boost, Boost-Jam, and Boost-Build via MacPorts
(macports.org), and it should build in Terminal with 'bjam', of course
you can add --prefix for an installation directory and link=static if
you're not a big dylib fan. As for compiling your own projects... it
should work after that.

On Sat, Jan 16, 2010 at 7:43 PM, Tomas Cokis <[hidden email]> wrote:

>
> It won't even let me pass classes as a pointer - I think there must be
> something wrong with my build. Sigh.
>
> Does anyone know if theres a binary (Mac) I can find somewhere?
> --
> View this message in context: http://old.nabble.com/Uncertain-about-luabind-tp27160576p27196008.html
> Sent from the Lua C++ Bind mailing list archive at Nabble.com.
>
>
> ------------------------------------------------------------------------------
> Throughout its 18-year history, RSA Conference consistently attracts the
> world's best and brightest in the field, creating opportunities for Conference
> attendees to learn about information security's most important issues through
> interactions with peers, luminaries and emerging and established companies.
> http://p.sf.net/sfu/rsaconf-dev2dev
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>

------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user