Skip to content
Extraits de code Groupes Projets

Lua cpp expose

Comparer et
4 files
+ 185
5
Comparer les modifications
  • Côte à côte
  • En ligne

Fichiers

+ 58
0
#include "LuaScript.hh"
#include "lua.hpp"
using namespace Vivy::Script;
/// LuaContext implementation
LuaContext::LuaContext() noexcept
: L(luaL_newstate())
{
luaL_openlibs(L);
}
LuaContext::~LuaContext() noexcept
{
}
lua_State *
LuaContext::getState() const noexcept
{
return L;
}
int
LuaContext::loadFile(const char *file) noexcept
{
int rc = luaL_loadfile(L, file);
if (rc == LUA_OK)
return lua_pcall(L, 0, LUA_MULTRET, 0);
return rc;
}
/// SampleObject implementation
SampleObject::SampleObject() noexcept
{
}
int
SampleObject::foo(lua_State *L) noexcept
{
SampleObject *obj = CHECK(L, 1);
double bar = luaL_checknumber(L, 2);
fprintf(stderr, "SampleObject(%p)::foo -> %f\n", static_cast<void *>(obj), bar);
return 0;
}
LuaMethodTable
SampleObject::getMetaMethods() noexcept
{
return { LUA_DECL_METHOD(SampleObject, foo) };
}
LuaMethodTable
SampleObject::getMethods() noexcept
{
return { luaRegDefaultGC };
}
Chargement en cours