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

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();

        luabind::module(state) [

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")
        log("A is nil")

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

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

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.
luabind-user mailing list
[hidden email]