Sign in to follow this  

[LUA][Luabind] loadlib not working at all [solved]

This topic is 2852 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey there, I'm trying to implement lua into our game using luabind, but it turns out to be harder than expected. I have a project containing only one file with the following content:
#include <iostream>
#include <luabind/luabind.hpp>

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

extern "C" int init(lua_State* L)
{
    using namespace luabind;

    open(L);

    module(L)
    [
        def("greet", &greet)
    ];

    return 0;
}



It's the exact same content as in the luabind tutorial. I compile it as a dll, and the compiling works quite well. Now I try to run the following script:
function main()
	mylib = package.loadlib('test_d.dll', 'init')
	assert(mylib)
end

main()


Now guess what... the assertion always triggers. Yes, the name is correct and both the lua and the dll file are in the same folder. I seriously have no idea what's happening here. Is it possible that something is wrong with the .dll? I merely created an empty c++ project, changed it to create a dll and inserted the file you saw as the only file. Using the release version doesn't work, either. [Edited by - TheSHEEEP on February 26, 2010 12:26:32 AM]

Share this post


Link to post
Share on other sites
Yeah, I was wondering about that too. Should have listened to that feeling ;)

I have replaced the init-function header with the following:
extern "C" __declspec(dllexport) int init(lua_State* L)



And the lua-file now looks like this:

function main()
mylib = package.loadlib('CharCreation_d.dll', 'init')
mylib()
greet()
end

main()



And it works!
Lesson learned today: Don't trust tutorials ;)

Thank you for the input there.


Also, an additional question (I don't want to open up an extra thread for that if I don't have to):

In our game, we will most likely have dozens of lua files. In all of them, we will want to use the library we create. Using loadlib in that many files during the runtime of the game somehow doesn't sound like a good idea to me.

Is there any other way of getting the functions of the library to work in many lua files without having to use loadlib in each one of them?

[Edited by - TheSHEEEP on February 26, 2010 12:25:05 AM]

Share this post


Link to post
Share on other sites

This topic is 2852 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this