Files
pip/lib/main/lua/pip_lua.h
2020-07-22 22:20:54 +03:00

40 lines
781 B
C++

#ifndef PIP_LUA_H
#define PIP_LUA_H
extern "C" {
# include "lua.h"
# include "lauxlib.h"
# include "lualib.h"
}
#include <LuaBridge/LuaBridge.h>
#include "pistring.h"
namespace luabridge {
template <>
struct Stack <PIString> {
static void push (lua_State* L, PIString const& str) {
lua_pushstring(L, str.dataUTF8());
}
static PIString get (lua_State* L, int index) {
if (lua_type(L, index) == LUA_TSTRING) {
const char* str = lua_tostring(L, index);
return PIString::fromUTF8(str);
}
lua_pushvalue(L, index);
const char* str = lua_tostring(L, -1);
PIString string = PIString::fromUTF8(str);
lua_pop(L, 1);
return string;
}
static bool isInstance (lua_State* L, int index) {
return lua_type(L, index) == LUA_TSTRING;
}
};
}
#endif // PIP_LUA_H