Strange behavour in Lua classes - 0.9.1

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

Strange behavour in Lua classes - 0.9.1

Nigel Atkinson-2
I thought I was loosing for while, it but I think I managed to isolate a
bug...

print 'Hello from Lua!'

class 'test'

function test:__init()
    print 'Initialise class'
    print( self.a )
    print( self.b )
    print( self.c )
    print( self.d )

    self.a = 'One'
    self.b = 'Two'
    self.c = 'Three'
    self.d = 'Four'
end

t1 = test()
t2 = test()

print '2nd test.'

t1.a = 'Something different'
print( t2.a )

t1.b = 'Oh oh!'
print( t2.b )

print 'End'

Is that correct code in the init function?  I thought it was ok, but
it's 'linking' all but the first class member (a).

Here's what I get from running it.

Hello from Lua!
Initialise class
nil
nil
nil
nil
Initialise class
nil
Two
Three
Four
2nd test.
One
Oh oh!
End


Some thing screwy with the way the code for __newindex or __index works
perhaps? Or am I doing something dumb.

Nigel


------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing.
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Strange behavour in Lua classes - 0.9.1

Daniel Wallin
Nigel Atkinson wrote:
> I thought I was loosing for while, it but I think I managed to isolate a
> bug...

Yes, you have. Thanks! I pushed a fix on the 0.9 branch.

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

------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing.
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Strange behavour in Lua classes - 0.9.1

Nigel Atkinson-2
Cool thanks, Daniel.  I'll be interested to see what you changed.  I had
a look at set_instance_value & get_instance_value in object_rep.cpp but
could not figure it out.

Nigel

On Mon, 2009-12-07 at 15:49 +0100, Daniel Wallin wrote:
> Nigel Atkinson wrote:
> > I thought I was loosing for while, it but I think I managed to isolate a
> > bug...
>
> Yes, you have. Thanks! I pushed a fix on the 0.9 branch.
>



------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing.
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Strange behavour in Lua classes - 0.9.1

Evan Wies
http://github.com/luabind/luabind/commit/4af7e5ab72ee410b6d3689a846c47fcc39f5c268


Nigel Atkinson wrote:

> Cool thanks, Daniel.  I'll be interested to see what you changed.  I had
> a look at set_instance_value & get_instance_value in object_rep.cpp but
> could not figure it out.
>
> Nigel
>
> On Mon, 2009-12-07 at 15:49 +0100, Daniel Wallin wrote:
>> Nigel Atkinson wrote:
>>> I thought I was loosing for while, it but I think I managed to isolate a
>>> bug...
>> Yes, you have. Thanks! I pushed a fix on the 0.9 branch.
>>
>
>
>
> ------------------------------------------------------------------------------
> Join us December 9, 2009 for the Red Hat Virtual Experience,
> a free event focused on virtualization and cloud computing.
> Attend in-depth sessions from your desk. Your couch. Anywhere.
> http://p.sf.net/sfu/redhat-sfdev2dev


------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing.
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

For 0.9? Avoiding string copy

Kristoffer Danielsson
In reply to this post by Daniel Wallin
Please see my old post: http://old.nabble.com/call_function-with-parts-of-string-%2B-length-p24970722.html
 
Any chance you could add such a wrapper for 0.9? It's really painful to copy strings that do not need to be copied!
 
/Chris


Uppgradera till en ny och säkrare version av Windows Live Messenger! Uppgradera till en ny och säkrare version av Windows Live Messenger!
------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev

_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: For 0.9? Avoiding string copy

Linker
Copying string is not a important thing. 
First benchmark it, then optimize it.

On Wed, Dec 9, 2009 at 20:50, Kristoffer Danielsson <[hidden email]> wrote:
Please see my old post: http://old.nabble.com/call_function-with-parts-of-string-%2B-length-p24970722.html
 
Any chance you could add such a wrapper for 0.9? It's really painful to copy strings that do not need to be copied!
 
/Chris


Uppgradera till en ny och säkrare version av Windows Live Messenger! Uppgradera till en ny och säkrare version av Windows Live Messenger!

------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev

_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user




--
Regards,
Linker Lin
[hidden email]

------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev

_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: For 0.9? Avoiding string copy

Kristoffer Danielsson
If I process a 1000 files, line by line, then this does make a difference.
 
Also, I believe the LUA api does provide such a function (lua_pushstring?), so naturally luabind would support it too.
 

From: [hidden email]
Date: Wed, 9 Dec 2009 22:35:33 +0800
To: [hidden email]
Subject: Re: [luabind] For 0.9? Avoiding string copy

Copying string is not a important thing. 
First benchmark it, then optimize it.

On Wed, Dec 9, 2009 at 20:50, Kristoffer Danielsson <[hidden email]> wrote:
Please see my old post: http://old.nabble.com/call_function-with-parts-of-string-%2B-length-p24970722.html
 
Any chance you could add such a wrapper for 0.9? It's really painful to copy strings that do not need to be copied!
 
/Chris


Uppgradera till en ny och säkrare version av Windows Live Messenger! Uppgradera till en ny och säkrare version av Windows Live Messenger!

------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev

_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user




--
Regards,
Linker Lin
[hidden email]


Yes! Windows 7 gör din dator bättre och enklare Yes! Windows 7 gör din dator bättre och enklare
------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev

_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: For 0.9? Avoiding string copy

Daniel Wallin
In reply to this post by Kristoffer Danielsson
Kristoffer Danielsson wrote:
> Any chance you could add such a wrapper for 0.9? It's really painful
> to copy strings that do not need to be copied!

0.9 is (mostly) in feature freeze, so I won't add anything like that at
least for now. You can easily do it by yourself though:

  struct cstring_with_length
  {
      cstring_with_length(char const* s, std::size_t len)
        : s(s)
        , len(len)
      {}

      char const* s;
      std::size_t len;
  };

  namespace luabind
  {

    template <>
    struct default_converter<cstring_with_length>
      : native_converter_base<cstring_with_length>
    {
        void to(lua_State* L, cstring_with_length const& str)
        {
            lua_pushlstring(L, str.s, str.len);
        }
    };

  } // namespace luabind

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

------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: For 0.9? Avoiding string copy

Kristoffer Danielsson
Thanks a lot!
 
So I simply instantiate this class and pass it to call_function?
 

> Date: Wed, 9 Dec 2009 17:58:01 +0100
> From: [hidden email]
> To: [hidden email]
> Subject: Re: [luabind] For 0.9? Avoiding string copy
>
> Kristoffer Danielsson wrote:
> > Any chance you could add such a wrapper for 0.9? It's really painful
> > to copy strings that do not need to be copied!
>
> 0.9 is (mostly) in feature freeze, so I won't add anything like that at
> least for now. You can easily do it by yourself though:
>
> struct cstring_with_length
> {
> cstring_with_length(char const* s, std::size_t len)
> : s(s)
> , len(len)
> {}
>
> char const* s;
> std::size_t len;
> };
>
> namespace luabind
> {
>
> template <>
> struct default_converter<cstring_with_length>
> : native_converter_base<cstring_with_length>
> {
> void to(lua_State* L, cstring_with_length const& str)
> {
> lua_pushlstring(L, str.s, str.len);
> }
> };
>
> } // namespace luabind
>
> --
> Daniel Wallin
> BoostPro Computing
> http://www.boostpro.com
>
> ------------------------------------------------------------------------------
> Return on Information:
> Google Enterprise Search pays you back
> Get the facts.
> http://p.sf.net/sfu/google-dev2dev
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user


Hitta kärleken! Klicka här Hitta en dator som passar dig!
------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev

_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: For 0.9? Avoiding string copy

Kristoffer Danielsson
In reply to this post by Daniel Wallin
I tried your code with 0.9 and got a lot of compilation errors. What did I do wrong?
 
 
luabind\luabind\detail\inheritance.hpp(21) : warning C4003: not enough actual parameters for macro 'max'
luabind\luabind\detail\inheritance.hpp(21) : error C2589: '(' : illegal token on right side of '::'
luabind\luabind\detail\inheritance.hpp(21) : error C2059: syntax error : '::'
luabind\luabind\detail\inheritance.hpp(21) : error C2059: syntax error : ')'
luabind\luabind\detail\inheritance.hpp(21) : error C2059: syntax error : ')'
luabind\luabind\detail\call.hpp(54) : warning C4003: not enough actual parameters for macro 'max'
luabind\luabind\detail\call.hpp(53) : error C2589: '(' : illegal token on right side of '::'
luabind\luabind\detail\call.hpp(53) : error C2143: syntax error : missing ')' before '::'
luabind\luabind\detail\call.hpp(53) : error C2612: trailing '::' illegal in base/member initializer list
luabind\luabind\detail\call.hpp(53) : error C2589: '(' : illegal token on right side of '::'
luabind\luabind\detail\call.hpp(53) : error C2143: syntax error : missing ';' before '::'
luabind\luabind\detail\call.hpp(53) : error C2059: syntax error : ')'
luabind\luabind\detail\call.hpp(56) : error C2143: syntax error : missing ';' before '{'
luabind\luabind\detail\call.hpp(70) : error C2951: template declarations are only permitted at global, namespace, or class scope
luabind\luabind\detail\call.hpp(79) : error C2888: 'int invoke0(lua_State *,const luabind::detail::function_object &,luabind::detail::invoke_context &,const F &,Signature,const Policies &,IsVoid,boost::mpl::true_)' : symbol cannot be defined within namespace 'detail'
luabind\luabind\detail\call.hpp(79) : fatal error C1506: unrecoverable block scoping error

 
Thanks!

 

> Date: Wed, 9 Dec 2009 17:58:01 +0100
> From: [hidden email]
> To: [hidden email]
> Subject: Re: [luabind] For 0.9? Avoiding string copy
>
> Kristoffer Danielsson wrote:
> > Any chance you could add such a wrapper for 0.9? It's really painful
> > to copy strings that do not need to be copied!
>
> 0.9 is (mostly) in feature freeze, so I won't add anything like that at
> least for now. You can easily do it by yourself though:
>
> struct cstring_with_length
> {
> cstring_with_length(char const* s, std::size_t len)
> : s(s)
> , len(len)
> {}
>
> char const* s;
> std::size_t len;
> };
>
> namespace luabind
> {
>
> template <>
> struct default_converter<cstring_with_length>
> : native_converter_base<cstring_with_length>
> {
> void to(lua_State* L, cstring_with_length const& str)
> {
> lua_pushlstring(L, str.s, str.len);
> }
> };
>
> } // namespace luabind
>
> --
> Daniel Wallin
> BoostPro Computing
> http://www.boostpro.com
>
> ------------------------------------------------------------------------------
> Return on Information:
> Google Enterprise Search pays you back
> Get the facts.
> http://p.sf.net/sfu/google-dev2dev
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user


Hitta kärleken! Klicka här Hitta en dator som passar dig!
------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev

_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: For 0.9? Avoiding string copy

Kristoffer Danielsson
Hmm... obviously, I included windows.h and min() and max() were defined.
 
I believe you can patch luabind to explicitly not use these defines, as described here:
http://article.gmane.org/gmane.comp.lang.lua.bind.user/939
 

 

From: [hidden email]
To: [hidden email]
Date: Sat, 12 Dec 2009 21:24:00 +0100
Subject: Re: [luabind] For 0.9? Avoiding string copy

I tried your code with 0.9 and got a lot of compilation errors. What did I do wrong?
 
 
luabind\luabind\detail\inheritance.hpp(21) : warning C4003: not enough actual parameters for macro 'max'
luabind\luabind\detail\inheritance.hpp(21) : error C2589: '(' : illegal token on right side of '::'
luabind\luabind\detail\inheritance.hpp(21) : error C2059: syntax error : '::'
luabind\luabind\detail\inheritance.hpp(21) : error C2059: syntax error : ')'
luabind\luabind\detail\inheritance.hpp(21) : error C2059: syntax error : ')'
luabind\luabind\detail\call.hpp(54) : warning C4003: not enough actual parameters for macro 'max'
luabind\luabind\detail\call.hpp(53) : error C2589: '(' : illegal token on right side of '::'
luabind\luabind\detail\call.hpp(53) : error C2143: syntax error : missing ')' before '::'
luabind\luabind\detail\call.hpp(53) : error C2612: trailing '::' illegal in base/member initializer list
luabind\luabind\detail\call.hpp(53) : error C2589: '(' : illegal token on right side of '::'
luabind\luabind\detail\call.hpp(53) : error C2143: syntax error : missing ';' before '::'
luabind\luabind\detail\call.hpp(53) : error C2059: syntax error : ')'
luabind\luabind\detail\call.hpp(56) : error C2143: syntax error : missing ';' before '{'
luabind\luabind\detail\call.hpp(70) : error C2951: template declarations are only permitted at global, namespace, or class scope
luabind\luabind\detail\call.hpp(79) : error C2888: 'int invoke0(lua_State *,const luabind::detail::function_object &,luabind::detail::invoke_context &,const F &,Signature,const Policies &,IsVoid,boost::mpl::true_)' : symbol cannot be defined within namespace 'detail'
luabind\luabind\detail\call.hpp(79) : fatal error C1506: unrecoverable block scoping error

 
Thanks!

 

> Date: Wed, 9 Dec 2009 17:58:01 +0100
> From: [hidden email]
> To: [hidden email]
> Subject: Re: [luabind] For 0.9? Avoiding string copy
>
> Kristoffer Danielsson wrote:
> > Any chance you could add such a wrapper for 0.9? It's really painful
> > to copy strings that do not need to be copied!
>
> 0.9 is (mostly) in feature freeze, so I won't add anything like that at
> least for now. You can easily do it by yourself though:
>
> struct cstring_with_length
> {
> cstring_with_length(char const* s, std::size_t len)
> : s(s)
> , len(len)
> {}
>
> char const* s;
> std::size_t len;
> };
>
> namespace luabind
> {
>
> template <>
> struct default_converter<cstring_with_length>
> : native_converter_base<cstring_with_length>
> {
> void to(lua_State* L, cstring_with_length const& str)
> {
> lua_pushlstring(L, str.s, str.len);
> }
> };
>
> } // namespace luabind
>
> --
> Daniel Wallin
> BoostPro Computing
> http://www.boostpro.com
>
> ------------------------------------------------------------------------------
> Return on Information:
> Google Enterprise Search pays you back
> Get the facts.
> http://p.sf.net/sfu/google-dev2dev
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user


Hitta kärleken! Klicka här Hitta en dator som passar dig!

Ladda ner nya Internet Explorer 8! Ladda ner nya Internet Explorer 8!
------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev

_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: For 0.9? Avoiding string copy

Daniel Wallin
Kristoffer Danielsson wrote:
> Hmm... obviously, I included windows.h and min() and max() were defined.
>
>  
>
> I believe you can patch luabind to explicitly not use these defines, as described here:
>
> http://article.gmane.org/gmane.comp.lang.lua.bind.user/939

Yes, thanks. Fixed in the 0.9 branch.

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

------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: For 0.9? Avoiding string copy

liam mail


2009/12/13 Daniel Wallin <[hidden email]>
Kristoffer Danielsson wrote:
> Hmm... obviously, I included windows.h and min() and max() were defined.
>
>
>
> I believe you can patch luabind to explicitly not use these defines, as described here:
>
> http://article.gmane.org/gmane.comp.lang.lua.bind.user/939

Yes, thanks. Fixed in the 0.9 branch.

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

------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
 
Actually the better method is not to use the define yet wrap the function calls in parenthesis.
For example (std::limits<int>::max)() exspecially if you use a max or min in a header which user code will see, as this removes the need for the user to also use the macro.

------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev

_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: For 0.9? Avoiding string copy

liam mail
Actually the better method is not to use the define yet wrap the function calls in parenthesis.
For example (std::limits<int>::max)() exspecially if you use a max or min in a header which user code will see, as this removes the need for the user to also use the macro.

Hmm then again that thread does mention it and I see this is the diff in branch. Sorry ignore me.

------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev

_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user