Skip to content
/ glua Public

Minimalistic reflection-based lua bindings for C++

License

Notifications You must be signed in to change notification settings

cyanidle/glua

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GLUA

Simple lua binding generator.

static int Func(int a, int b) {
    return a + b;
}

// basic
lua_register(L, "Func", glua::Wrap<Func>);
struct Person {
    std::string name;
    int age;

    std::string Hello() {
        return "Hello " + name;
    }
};
DESCRIBE(Person, &_::name, &_::age, &_::Hello)

static std::string GreetAnother(Person* a, Person* b) {
    return "Hello from: " + a->name + " to: " + b->name;
}

// Add methods
glua::PushMethodsTable<Person>(L);
lua_pushcfunction(L, glua::Wrap<GreetAnother>);
lua_setfield(L, -2, "GreetAnother");
// Generic push
glua::Push(L, 123);
lua_setglobal(L, "num");
glua::Push(L, Person{"polina", 23});
lua_setglobal(L, "polina");
glua::Push(L, Person{"alexej", 22});
lua_setglobal(L, "alexej");
static int FuncOverload(lua_State* L, int a) {
    int b;
    if (lua_isinteger(L, 2)) {
        b = lua_tointeger(L, 2);
    } else {
        b = 123;
    }
    return a + b;
}

// use current state directly
lua_register(L, "FuncOverload", glua::Wrap<FuncOverload>);

About

Minimalistic reflection-based lua bindings for C++

Resources

License

Stars

Watchers

Forks

Packages

No packages published