PILuaProgram

This commit is contained in:
2020-07-22 23:00:31 +03:00
parent 16bbcddf50
commit 6f58388d8d
6 changed files with 142 additions and 12 deletions

View File

@@ -4,19 +4,22 @@
static const char * script
= "-- script.lua \n"
"test()\n"
"testString = \"LuaBridge works ававава!\" \n"
"number = 42 \n";
using namespace luabridge;
void test() {
piCout << "C function test";
}
int main() {
lua_State* L = luaL_newstate();
luaL_dostring(L, script);
luaL_openlibs(L);
lua_pcall(L, 0, 0, 0);
LuaRef s = getGlobal(L, "testString");
LuaRef n = getGlobal(L, "number");
PILuaProgram p;
p.getGlobalNamespace().addFunction("test", test);
if (!p.load(PIString::fromUTF8(script))) piCout << "error";
p.prepare();
luabridge::LuaRef s = p.getGlobal("testString");
luabridge::LuaRef n = p.getGlobal("number");
PIString luaString = s.cast<PIString>();
int answer = n.cast<int>();
piCout << luaString;