Possible bug loading shared libraries with def_readonly

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

Possible bug loading shared libraries with def_readonly

Tim Michals-2
Here is a brief description.  Create a shared library and have  class using the .def_readonly attribute... for example

What happens is the print(t.x) prints the following, the hello is the dll, the function is the print(t.x) this should print the value of t, just like the next statement, print(tt.x)

hello
function: 0086ADA0
ok
100



>>> This is the main.c file this is from the example test code file called test_class_info.cpp
// luaBindTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

// Copyright Daniel Wallin 2009. Use, modification and distribution is
// subject to the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <luabind/luabind.hpp>
#include <luabind/class_info.hpp>
#include <luabind/error.hpp>
#include <iostream>

extern "C" {
    #include "lua.h"
    #include "lstate.h"
    #include "ldo.h"
    #include "lgc.h"
    #include "lauxlib.h"
    #include "lualib.h"
    #include "lobject.h"

}


struct X
{
    void f()
    {}
    X():x(100), y(200){}

    int x;
    int y;
};

bool dostring(lua_State* L, const char* str)
{
    if (luaL_loadbuffer(L, str, std::strlen(str), str) || lua_pcall(L, 0, 0, 0))
    {
        const char* a = lua_tostring(L, -1);
        std::cout << a << "\n";
        lua_pop(L, 1);
        return true;
    }
    return false;
}


bool DOSTRING(struct lua_State *state_, std::string str)                  
{                                              
    try                                        
    {                                          
        dostring(state_, str.c_str());                
    }                                          
    catch (luabind::error const& e)            
    {      
        std::cout << "error" << e.what();
 //       TEST_ERROR(lua_tostring(e.state(), -1));
 //           lua_pop(L, 1);                     
    }                                          
    catch (std::string const& s)               
    {       
        std::cout << "error" << s;
   //     TEST_ERROR(s.c_str());                 
    }
    return true;
}



int _tmain(int argc, _TCHAR* argv[])
{
   using namespace luabind;

   lua_State* L = lua_open();
       luaL_openlibs(L);

   luabind::open(L);

    bind_class_info(L);

    module(L) [
        class_<X>("X")
            .def(constructor<>())
            .def("f", &X::f)
            .def_readonly("x", &X::x)
            .def_readonly("y", &X::y)
    ];

    DOSTRING(L,
        "x = X()\n"
        "info = class_info(x)\n"
        "assert(info.name == 'X')\n"
        "assert(info.methods['f'] == x.f)\n"
        "assert(info.methods['__init'] == x.__init)\n"
        "assert(info.attributes[1] == 'y')\n"
        "assert(info.attributes[2] == 'x')\n"
        "require('luabindLaterLoader')\n"
        "t = YY()\n"
        "print(t.x)\n"
        "print('ok')\n"
        "tt=X()\n"
        "print(tt.x)\n"


    );
    return 0;
}

The shared loadable module or dll in my case
// Copyright (c) 2005 Daniel Wallin and Arvid Norberg

// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.

extern "C"
{
    #include "lua.h"
    #include "lualib.h"
    #include "lauxlib.h"
}

#include <iostream>
#include <luabind/luabind.hpp>

#ifdef WIN32
#ifdef LUABINDLATERLOADER_EXPORTS
#define PLUGIN_API __declspec(dllexport)
#else
#define PLUGIN_API __declspec(dllimport)
#endif

#else //LINUX
#define SIMPLECPLUGIN_API __attribute__ ((visibility("default")))
#endif


void greet()
{
    std::cout << "hello world!\n";
}


struct YY
{
    YY():x(10), y(-10){}
    void f()
    {}

    int x;
    int y;
};




bool PLUGIN_API bind_Plugin(lua_State* L)
{
using namespace luabind;  

    if (L == NULL)
        return false;

    try
    {

  //  open(L);

    module(L)
    [
         class_<YY>("YY")
            .def(constructor<>())
            .def("f", &YY::f)
            .def_readonly("x", &YY::x)
            .def_readonly("y", &YY::y)
            ,
        def("greet", &greet)
    ];
   
    } catch ( ... )
    {
        return false;
    }

    return true;
}

extern "C" int PLUGIN_API luaopen_luabindLaterLoader(lua_State *L)
{
    puts("hello");
    bind_Plugin(L);
    return 0;
}


Windows Live™ SkyDrive™: Get 25 GB of free online storage. Get it on your BlackBerry or iPhone.
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug loading shared libraries with def_readonly

Tim Michals-2
It looks like this only happens when you are doing a package.loadlib and require, loading a lua module.  You can call the registration all day long on multiple classes and it will work, only when you do a require or loadlib does this have this problem...


From: [hidden email]
To: [hidden email]
Date: Wed, 10 Jun 2009 16:04:08 +0000
Subject: [luabind] Possible bug loading shared libraries with def_readonly

Here is a brief description.  Create a shared library and have  class using the .def_readonly attribute... for example

What happens is the print(t.x) prints the following, the hello is the dll, the function is the print(t.x) this should print the value of t, just like the next statement, print(tt.x)

hello
function: 0086ADA0
ok
100



>>> This is the main.c file this is from the example test code file called test_class_info.cpp
// luaBindTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

// Copyright Daniel Wallin 2009. Use, modification and distribution is
// subject to the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <luabind/luabind.hpp>
#include <luabind/class_info.hpp>
#include <luabind/error.hpp>
#include <iostream>

extern "C" {
    #include "lua.h"
    #include "lstate.h"
    #include "ldo.h"
    #include "lgc.h"
    #include "lauxlib.h"
    #include "lualib.h"
    #include "lobject.h"

}


struct X
{
    void f()
    {}
    X():x(100), y(200){}

    int x;
    int y;
};

bool dostring(lua_State* L, const char* str)
{
    if (luaL_loadbuffer(L, str, std::strlen(str), str) || lua_pcall(L, 0, 0, 0))
    {
        const char* a = lua_tostring(L, -1);
        std::cout << a << "\n";
        lua_pop(L, 1);
        return true;
    }
    return false;
}


bool DOSTRING(struct lua_State *state_, std::string str)                  
{                                              
    try                                        
    {                                          
        dostring(state_, str.c_str());                
    }                                          
    catch (luabind::error const& e)            
    {      
        std::cout << "error" << e.what();
 //       TEST_ERROR(lua_tostring(e.state(), -1));
 //           lua_pop(L, 1);                     
    }                                          
    catch (std::string const& s)               
    {       
        std::cout << "error" << s;
   //     TEST_ERROR(s.c_str());                 
    }
    return true;
}



int _tmain(int argc, _TCHAR* argv[])
{
   using namespace luabind;

   lua_State* L = lua_open();
       luaL_openlibs(L);

   luabind::open(L);

    bind_class_info(L);

    module(L) [
        class_<X>("X")
            .def(constructor<>())
            .def("f", &X::f)
            .def_readonly("x", &X::x)
            .def_readonly("y", &X::y)
    ];

    DOSTRING(L,
        "x = X()\n"
        "info = class_info(x)\n"
        "assert(info.name == 'X')\n"
        "assert(info.methods['f'] == x.f)\n"
        "assert(info.methods['__init'] == x.__init)\n"
        "assert(info.attributes[1] == 'y')\n"
        "assert(info.attributes[2] == 'x')\n"
        "require('luabindLaterLoader')\n"
        "t = YY()\n"
        "print(t.x)\n"
        "print('ok')\n"
        "tt=X()\n"
        "print(tt.x)\n"


    );
    return 0;
}

The shared loadable module or dll in my case
// Copyright (c) 2005 Daniel Wallin and Arvid Norberg

// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.

extern "C"
{
    #include "lua.h"
    #include "lualib.h"
    #include "lauxlib.h"
}

#include <iostream>
#include <luabind/luabind.hpp>

#ifdef WIN32
#ifdef LUABINDLATERLOADER_EXPORTS
#define PLUGIN_API __declspec(dllexport)
#else
#define PLUGIN_API __declspec(dllimport)
#endif

#else //LINUX
#define SIMPLECPLUGIN_API __attribute__ ((visibility("default")))
#endif


void greet()
{
    std::cout << "hello world!\n";
}


struct YY
{
    YY():x(10), y(-10){}
    void f()
    {}

    int x;
    int y;
};




bool PLUGIN_API bind_Plugin(lua_State* L)
{
using namespace luabind;  

    if (L == NULL)
        return false;

    try
    {

  //  open(L);

    module(L)
    [
         class_<YY>("YY")
            .def(constructor<>())
            .def("f", &YY::f)
            .def_readonly("x", &YY::x)
            .def_readonly("y", &YY::y)
            ,
        def("greet", &greet)
    ];
   
    } catch ( ... )
    {
        return false;
    }

    return true;
}

extern "C" int PLUGIN_API luaopen_luabindLaterLoader(lua_State *L)
{
    puts("hello");
    bind_Plugin(L);
    return 0;
}


Windows Live™ SkyDrive™: Get 25 GB of free online storage. Get it on your BlackBerry or iPhone.

Insert movie times and more without leaving Hotmail®. See how.
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug loading shared libraries with def_readonly

Tim Michals-2
same ole issue that was reported some time ago, did not compile the code correctly!!! Problem solved...


From: [hidden email]
To: [hidden email]
Date: Wed, 10 Jun 2009 17:07:43 +0000
Subject: Re: [luabind] Possible bug loading shared libraries with def_readonly

It looks like this only happens when you are doing a package.loadlib and require, loading a lua module.  You can call the registration all day long on multiple classes and it will work, only when you do a require or loadlib does this have this problem...


From: [hidden email]
To: [hidden email]
Date: Wed, 10 Jun 2009 16:04:08 +0000
Subject: [luabind] Possible bug loading shared libraries with def_readonly

Here is a brief description.  Create a shared library and have  class using the .def_readonly attribute... for example

What happens is the print(t.x) prints the following, the hello is the dll, the function is the print(t.x) this should print the value of t, just like the next statement, print(tt.x)

hello
function: 0086ADA0
ok
100



>>> This is the main.c file this is from the example test code file called test_class_info.cpp
// luaBindTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

// Copyright Daniel Wallin 2009. Use, modification and distribution is
// subject to the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <luabind/luabind.hpp>
#include <luabind/class_info.hpp>
#include <luabind/error.hpp>
#include <iostream>

extern "C" {
    #include "lua.h"
    #include "lstate.h"
    #include "ldo.h"
    #include "lgc.h"
    #include "lauxlib.h"
    #include "lualib.h"
    #include "lobject.h"

}


struct X
{
    void f()
    {}
    X():x(100), y(200){}

    int x;
    int y;
};

bool dostring(lua_State* L, const char* str)
{
    if (luaL_loadbuffer(L, str, std::strlen(str), str) || lua_pcall(L, 0, 0, 0))
    {
        const char* a = lua_tostring(L, -1);
        std::cout << a << "\n";
        lua_pop(L, 1);
        return true;
    }
    return false;
}


bool DOSTRING(struct lua_State *state_, std::string str)                  
{                                              
    try                                        
    {                                          
        dostring(state_, str.c_str());                
    }                                          
    catch (luabind::error const& e)            
    {      
        std::cout << "error" << e.what();
 //       TEST_ERROR(lua_tostring(e.state(), -1));
 //           lua_pop(L, 1);                     
    }                                          
    catch (std::string const& s)               
    {       
        std::cout << "error" << s;
   //     TEST_ERROR(s.c_str());                 
    }
    return true;
}



int _tmain(int argc, _TCHAR* argv[])
{
   using namespace luabind;

   lua_State* L = lua_open();
       luaL_openlibs(L);

   luabind::open(L);

    bind_class_info(L);

    module(L) [
        class_<X>("X")
            .def(constructor<>())
            .def("f", &X::f)
            .def_readonly("x", &X::x)
            .def_readonly("y", &X::y)
    ];

    DOSTRING(L,
        "x = X()\n"
        "info = class_info(x)\n"
        "assert(info.name == 'X')\n"
        "assert(info.methods['f'] == x.f)\n"
        "assert(info.methods['__init'] == x.__init)\n"
        "assert(info.attributes[1] == 'y')\n"
        "assert(info.attributes[2] == 'x')\n"
        "require('luabindLaterLoader')\n"
        "t = YY()\n"
        "print(t.x)\n"
        "print('ok')\n"
        "tt=X()\n"
        "print(tt.x)\n"


    );
    return 0;
}

The shared loadable module or dll in my case
// Copyright (c) 2005 Daniel Wallin and Arvid Norberg

// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.

extern "C"
{
    #include "lua.h"
    #include "lualib.h"
    #include "lauxlib.h"
}

#include <iostream>
#include <luabind/luabind.hpp>

#ifdef WIN32
#ifdef LUABINDLATERLOADER_EXPORTS
#define PLUGIN_API __declspec(dllexport)
#else
#define PLUGIN_API __declspec(dllimport)
#endif

#else //LINUX
#define SIMPLECPLUGIN_API __attribute__ ((visibility("default")))
#endif


void greet()
{
    std::cout << "hello world!\n";
}


struct YY
{
    YY():x(10), y(-10){}
    void f()
    {}

    int x;
    int y;
};




bool PLUGIN_API bind_Plugin(lua_State* L)
{
using namespace luabind;  

    if (L == NULL)
        return false;

    try
    {

  //  open(L);

    module(L)
    [
         class_<YY>("YY")
            .def(constructor<>())
            .def("f", &YY::f)
            .def_readonly("x", &YY::x)
            .def_readonly("y", &YY::y)
            ,
        def("greet", &greet)
    ];
   
    } catch ( ... )
    {
        return false;
    }

    return true;
}

extern "C" int PLUGIN_API luaopen_luabindLaterLoader(lua_State *L)
{
    puts("hello");
    bind_Plugin(L);
    return 0;
}


Windows Live™ SkyDrive™: Get 25 GB of free online storage. Get it on your BlackBerry or iPhone.

Insert movie times and more without leaving Hotmail®. See how.

Windows Live™ SkyDrive™: Get 25 GB of free online storage. Get it on your BlackBerry or iPhone.
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user