1. Alex Ames
  2. LuaWrapper
  3. Pull requests

Pull requests

#5 Merged
Repository
bazhenovc
Branch
default
Repository
alexames
Branch
default

Support for static class functions

Author
  1. Kirill Bazhenov
Reviewers
Description

Hi, that's me again.
I've added support for static class functions, e.g.:

struct Foo
{
    int DoSomething(int, const char*);
    static void DoSomethingElse(int a, int b, float c);
};

static luaL_reg Foo_metatable[] =
{
    { "DoSomething", luaU_func(&Foo::DoSomething) },
    { NULL, NULL }
};

static luaL_reg Foo_metatable_static[] =
{
    { "DoSomethingElse", luaU_staticfunc(&Foo::DoSomethingElse) },
    { NULL, NULL }
};

void RegisterFoo(lua_State* L)
{
    luaW_register<Foo>(L, "Foo", Foo_metatable_static, Foo_metatable);
}

That can be used in Lua like this:

local foo = Foo.new()
foo:DoSomething(42, 'The Ultimate Question of Life, the Universe, and Everything.') -- member function call
Foo:DoSomethingElse(30, 12, 3.1459) -- Static function call

Hope that can be useful.

Cheers,
Kirill.

P.S. Thank you for this awesome library.

  • Learn about pull requests

Comments (0)