Skip to content

Instantly share code, notes, and snippets.

@voidproc
Last active August 29, 2016 02:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voidproc/971a83bc0bfc4817243e861bc96beaac to your computer and use it in GitHub Desktop.
Save voidproc/971a83bc0bfc4817243e861bc96beaac to your computer and use it in GitHub Desktop.
Lua 5.2.4 + LuaBridge minimal example
// Siv3D : http://play-siv3d.hateblo.jp/
#include <Siv3D.hpp>
// Lua : https://www.lua.org/
#include <lua.hpp>
#pragma comment(lib, "lua52.lib")
// LuaBridge : https://github.com/vinniefalco/LuaBridge
#include <LuaBridge.h>
using namespace luabridge;
class A
{
public:
A(const int val) : val_(val)
{
}
int f()
{
Println(L"f() : val=", val_);
return 123 + val_;
}
private:
int val_;
};
void Main()
{
// Initialize Lua
lua_State* L = luaL_newstate();
luaL_openlibs(L);
luaL_dostring(L,
"function luafunc(e)\n"
" return e:f()\n"
"end\n"
);
// Register C++ classes using LuaBridge
getGlobalNamespace(L)
.beginNamespace("foo")
.beginClass<A>("A")
.addFunction("f", &A::f)
.endClass()
.endNamespace();
// Call Lua function
LuaRef luafunc = getGlobal(L, "luafunc");
A a(90000);
int ret = luafunc(&a);
Println(ret);
WaitKey();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment