0.9 VS2008 link error + strange 'attempt to call nil' issue

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

0.9 VS2008 link error + strange 'attempt to call nil' issue

Matt Holmes-3
Hello,

First off, let me say that these questions may have been answered, but try as I might, I can't find a way to search the archive, so I can't tell. I've looked back quite a few months in the archive and saw nothing like my problem, so I decided to send in a question.

First off, I build luabind from the 0.9 sources using bjam and MSVC9 (auto-detected by boost.build because I was in my VS2008 command line environment). I built both the debug and release versions of the library.

After putting a call_function call in to my code, I started to recieve the following link error (when linking against the debug library):

Error    1    error LNK2001: unresolved external symbol "private: static unsigned int const luabind::detail::class_id_map::local_id_base" (?local_id_base@class_id_map@detail@luabind@@0IB)    Engine.obj    Tachyon

I was able to get around this with an absolute hack, which was to instantiate the static variable in one of my compiler units, like so:

unsigned int const luabind::detail::class_id_map::local_id_base =
    std::numeric_limits<unsigned int>::max() / 2;

Again, this is a total hack and not something I like having in my code.

Now I can compile, and I can run scripts, and I can even call globally defined functions. If I try and do anything with an instance of a defined class, even check it for nil, I get an 'attempt to call nil' error.

That may seem somewhat confusing, but let me show you with code:

Here is how I define the class:
    luabind::scope Actor::bind() {
        using namespace luabind;
        return class_<Actor>("Actor")
            .property("tag", &Actor::getTag)
            .property("name", &Actor::getName, &Actor::setName);
    }

    luabind::scope ScriptingService::bindCoreApi() {
        using namespace luabind;
        return def ("log", &global_log);
    }

    void ScriptingService::openContext(Scriptable* scriptable) {
        lua_State* state = lua_open();
        luaopen_base(state);
        luaopen_math(state);
        luaopen_string(state);
        luaopen_table(state);

        luabind::open(state);
        scriptable->setState(state);
       
        luabind::module(state) [
            bindCoreApi(),
            scriptable->bind()
        ];
    }

In this case, Actor is a Scriptable, and is being passed in to openContext. It's bind is correctly being called, and the class_ scope is being returned.

Now if I execute the following Lua on that lua_State:

function testEvent(a)
    if a ~= nil
        log("A is not nil")
    else
        log("A is nil")
    end
end

I will get an 'attempt to call nil' error, but if I do something like:

function testEvent(a)
    log("Hello World")
end

It works fine, so I know the log global function is registered and working.

I call the function like so:

luabind::call_function<void>(_state, "testEvent", a);

where a is a non-null Actor*.

Is there something obviously wrong here? And if this has been answered elsewhere, feel free to point me to that, and an archive search if one exists.

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user