Oberon00 / luabind

Luabind is a library that helps you create bindings between C++ and Lua.
http://oberon00.github.io/luabind/
Other
46 stars 13 forks source link

Document and have example for creating canonical Lua modules. #46

Closed dan-masek closed 3 years ago

dan-masek commented 3 years ago

From what I've read (and how the standard libraries seem to generally work in recent Lua versions) directly registering things into the global table is not ideal.

In order to create something that behaves the same way while using luabind, I came up with the following pattern:

#include <luabind/object.hpp>
#include <luabind/open.hpp>

extern "C" __declspec(dllexport) int luaopen_modulename(lua_State* L)
{
    luabind::open(L);

    luabind::object _M = luabind::newtable(L);
    luabind::module(_M)[
        // ...
    ]

    _M.push(L);

    return 1;
}

It might be beneficial to describe something like this in the documentation and perhaps have an example for it.

Oberon00 commented 3 years ago

AFAIR think documentation hasn't kept up at all with any of the new features added after the original luabind. I don't know if this fork is the best place to contribute it too though, as I no longer really maintain it.

These days, I have the impression that luabind is mostly used for legacy-reasons and new projects use other binding libraries. If you need suggestions, when I did a small survey way back in 2015, lua-intf, LuaBridge, selene and OOLua seemed promising. But since then I think, among others, sol and Sol2 (https://github.com/ThePhD/sol2) emerged and might be the best current option.

By the way, I think there is a more portable way than the Windows-specific __declspec(dllexport), namely BOOST_SYMBOL_EXPORT from Boost.Config.

dan-masek commented 3 years ago

OK, Thanks for the work you've done on your fork. I picked up luabind some 10 years ago, and at some point switched to your fork (and i might have used Ryan's one for a bit before that). So I'm one of those legacy users, and switching everything to another library is low value for effort (as long as this thing still works well enough, which is does).

Thanks for pointing out the alternatives. If I were starting now, I would have most likely gone with Sol2.

Good point about the BOOST_SYMBOL_EXPORT ... I mostly work on a single platform so this didn't come to my mind.