Skip to content

Instantly share code, notes, and snippets.

@progschj
Last active December 11, 2015 07:09
Show Gist options
  • Save progschj/4564649 to your computer and use it in GitHub Desktop.
Save progschj/4564649 to your computer and use it in GitHub Desktop.
Testcase for Luabridge Placing luabridge "registration" into different translation units can lead to types not being recognized correctly
#include "A.hpp"
#include <iostream>
#include <string>
#include <LuaBridge/LuaBridge.h>
std::string A::getName() const { return std::string("A"); }
void A::register_lua(lua_State *L)
{
using namespace luabridge;
getGlobalNamespace (L)
.beginNamespace ("test")
.beginClass <A> ("A")
.addConstructor<void(*)(void)>()
.addProperty("name", &A::getName)
.endClass ()
.endNamespace ();
}
#ifndef A_H
#define A_H
#include <string>
#include <lua5.2/lua.hpp>
struct A {
std::string getName() const;
static void register_lua(lua_State *L);
};
#endif
#include <iostream>
#include <string>
#include <lua5.2/lua.hpp>
#include <lua5.2/lualib.h>
#include <LuaBridge/LuaBridge.h>
#include "A.hpp"
void printA(A *a)
{
std::cout << a->getName() << std::endl;
}
int main(int argc, char *argv[]) {
int iarg;
lua_State *L = luaL_newstate();
luaL_openlibs(L);
A::register_lua(L);
{
using namespace luabridge;
getGlobalNamespace (L)
.addFunction ("printA", &printA);
}
int s = luaL_dostring(L,
"a = test.A()\n"
"printA(a)\n"
);
if(s != 0) {
std::cerr << "Error: " << lua_tostring(L, -1) << std::endl;
lua_pop(L, 1);
}
lua_close(L);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment