Last active
December 11, 2015 07:09
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 (); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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