PILuaProgram
This commit is contained in:
17
main.cpp
17
main.cpp
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user