version 2.24.0

New PIParseHelper class
This commit is contained in:
2021-05-05 00:41:22 +03:00
parent 8526ad1c30
commit 3c3a8ea177
5 changed files with 302 additions and 24 deletions

View File

@@ -1,27 +1,39 @@
#include "pip.h"
extern "C" {
# include "lua.h"
# include "lauxlib.h"
# include "lualib.h"
}
#include <LuaBridge/LuaBridge.h>
#include "pistring_std.h"
enum Header {
hInt = 1,
hString,
hVoid
};
static const char * script
= "-- script.lua \n"
"testString = \"LuaBridge works!\" \n"
"number = 42 \n";
class MyObj: public PIObject {
PIOBJECT(MyObj);
public:
EVENT_HANDLER1(void, methodI, int, i) {piCout << "methodI" << i;}
EVENT_HANDLER1(void, methodS, PIString, s) {piCout << "methodS" << s;}
EVENT_HANDLER0(void, method) {piCout << "method";}
};
using namespace luabridge;
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");
std::string luaString = s.cast<std::string>();
int answer = n.cast<int>();
piCout << StdString2PIString(luaString);
piCout << "And here's our number:" << answer;
MyObj o;
PIParseHelper<int> parser(&o);
parser.assign(hInt, o.HANDLER(methodI));
parser.assign(hString, o.HANDLER(methodS));
parser.assign(hVoid, o.HANDLER(method));
PIByteArray data;
data.clear();
data << 11;
parser.parse(hInt, data);
// methodI 11
data.clear();
data << PIString("text");
parser.parse(hString, data);
// methodS text
data.clear();
parser.parse(hVoid, data);
// method
}