PIP Lua Module
This commit is contained in:
47
main.cpp
47
main.cpp
@@ -1,55 +1,12 @@
|
||||
#include "pip.h"
|
||||
#ifdef PIP_LUA
|
||||
extern "C" {
|
||||
# include "lua.h"
|
||||
# include "lauxlib.h"
|
||||
# include "lualib.h"
|
||||
}
|
||||
#include <LuaBridge/LuaBridge.h>
|
||||
#include "pistring_std.h"
|
||||
#include "piluaprogram.h"
|
||||
|
||||
static const char * script
|
||||
= "-- script.lua \n"
|
||||
"testString = \"LuaBridge works!\" \n"
|
||||
"testString = \"LuaBridge works ававава!\" \n"
|
||||
"number = 42 \n";
|
||||
|
||||
namespace luabridge {
|
||||
|
||||
template <>
|
||||
struct Stack <PIString>
|
||||
{
|
||||
static void push (lua_State* L, PIString const& str)
|
||||
{
|
||||
lua_pushstring(L, str.dataAscii());
|
||||
}
|
||||
|
||||
static PIString get (lua_State* L, int index)
|
||||
{
|
||||
size_t len;
|
||||
if (lua_type (L, index) == LUA_TSTRING)
|
||||
{
|
||||
const char* str = lua_tolstring(L, index, &len);
|
||||
return PIString(str, len);
|
||||
}
|
||||
|
||||
// Lua reference manual:
|
||||
// If the value is a number, then lua_tolstring also changes the actual value in the stack to a string.
|
||||
// (This change confuses lua_next when lua_tolstring is applied to keys during a table traversal.)
|
||||
lua_pushvalue (L, index);
|
||||
const char* str = lua_tolstring(L, -1, &len);
|
||||
PIString string (str, len);
|
||||
lua_pop (L, 1); // Pop the temporary string
|
||||
return string;
|
||||
}
|
||||
|
||||
static bool isInstance (lua_State* L, int index)
|
||||
{
|
||||
return lua_type (L, index) == LUA_TSTRING;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
using namespace luabridge;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user