سؤال

I have been struggling for quite a while now. Whenever I try to define a class in luabind I get a assertion failure

assert( id < local_id_base ) in inheritance.hpp (luabind)

I have tried alot of different luabind forks without any success. Though they have all been compiled with boost 1.53 and Visual Studio 2012. Also with lua 5.2.1

This is the code I am using, just for

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

#include <luabind/luabind.hpp>
#include <luabind/class.hpp>
#include <luabind/function.hpp>
#include <luabind/object.hpp>


    class TestStruct 
    {
    public:
        TestStruct(const std::string& s): m_string(s) {}
        void printmsg() { printf("Works"); };
    private:
        int i; 
        std::string m_string;
    };


int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
                       _In_opt_ HINSTANCE hPrevInstance,
                       _In_ LPTSTR    lpCmdLine,
                       _In_ int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    lua_State* L = luaL_newstate();

    luaopen_io (L);
    luaopen_base(L);
    luaopen_table(L);
    luaopen_string(L);
    luaopen_math(L);

    using namespace luabind;

    open(L);

    module(L)
        [
            class_<TestStruct>("TestStruct")
            .def(constructor<const std::string&>())
            .def("printmsg", &TestStruct::printmsg)


        ];


    lua_close(L);

    return 0;
}

[SOLVED]

After reading around I got pretty much nowhere. So what I did was to build LuaBind and Lua 5.2.2 in the same project creating one lib instead of two separate ones.

هل كانت مفيدة؟

المحلول

Your class is local, hence is not visible to LuaBind's templates. Move the class out of the main().

If that doesn't help, check if you built LuaBind correctly - http://www.ogre3d.org/forums/viewtopic.php?f=2&t=75829

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top