ThePhD / sol2

Sol3 (sol2 v3.0) - a C++ <-> Lua API wrapper with advanced features and top notch performance - is here, and it's great! Documentation:
http://sol2.rtfd.io/
MIT License
4.06k stars 492 forks source link

Create a namespace table with functions #1562

Closed UltraEngine closed 6 months ago

UltraEngine commented 6 months ago

I want to make a table with functions added to it, to act as a namespace. Can anyone tell me how to do this correctly?:

    void BindCommands(sol::state* L)
    {
        sol::table t;

        t["Initialize"] = Steamworks::Initialize;
        t["Shutdown"] = Steamworks::Shutdown;
        t["Update"] = Steamworks::Update;

        L->set("Steamworks", t);
    }

Usage in Lua:

Steamworks.Initialize()
Steamworks.Update()
Steamworks.Shutdown()
UltraEngine commented 6 months ago

There is always way with sol...

    void BindCommands(sol::state* L)
    {
        sol::table t(*L, sol::create);

:)