Skip to content
Extraits de code Groupes Projets
Vérifiée Valider bc9b385d rédigé par Kubat's avatar Kubat
Parcourir les fichiers

SCRIPT: Begin implementation of declaration script classes

parent d633e0fe
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!16Add a way to execute a Lua file with Vivy in a click-click way
......@@ -93,12 +93,17 @@ OptionDeclaration::addOptionContent(lua_State *) noexcept
// JobDeclaration
JobDeclaration::JobDeclaration(lua_State *) noexcept {}
JobDeclaration::~JobDeclaration() noexcept {}
int
JobDeclaration::setName(lua_State *) noexcept
JobDeclaration::setName(lua_State *L) noexcept
{
std::size_t len = 0;
auto *const context = LuaContext::getContext(L);
JobDeclaration *const job = JobDeclaration::CHECK(L, 1);
const char *cStrName = luaL_checklstring(L, 2, &len);
job->name = std::string_view(cStrName, len);
err(context) << "Set name of job to " << job->name << "\n";
return 0;
}
......@@ -109,8 +114,14 @@ JobDeclaration::setOptions(lua_State *) noexcept
}
int
JobDeclaration::setImportFromScript(lua_State *) noexcept
JobDeclaration::setImportFromScript(lua_State *L) noexcept
{
std::size_t len = 0;
auto *const context = LuaContext::getContext(L);
JobDeclaration *const job = JobDeclaration::CHECK(L, 1);
const char *cStrName = luaL_checklstring(L, 2, &len);
job->parentScript = std::string_view(cStrName, len);
err(context) << "Set the name of the parent script to " << job->parentScript << "\n";
return 0;
}
......
......@@ -30,7 +30,7 @@ template <class Object> class CRTPLuaScriptObject {
protected:
static int GC(lua_State *L) noexcept
{
const Object *obj = reinterpret_cast<const Object *>(lua_topointer(L, 1));
const Object *const obj = reinterpret_cast<const Object *>(lua_topointer(L, 1));
auto *context = LuaContext::getContext(L);
err(context) << "Call destructor for " << Object::className << "\n";
obj->~Object();
......@@ -39,28 +39,22 @@ protected:
static int CREATE(lua_State *L) noexcept
{
Object *obj = reinterpret_cast<Object *>(lua_newuserdata(L, sizeof(Object)));
lua_settop(L, 0);
Object *const obj = reinterpret_cast<Object *>(lua_newuserdata(L, sizeof(Object)));
new (obj) Object(L);
luaL_getmetatable(L, Object::className);
lua_setmetatable(L, -2);
lua_setmetatable(L, 1);
return 1;
}
static inline constexpr luaL_Reg luaRegDefaultGC = { "__gc", GC };
public:
static Object *CHECK(lua_State *L, int index) noexcept
{
luaL_checktype(L, index, LUA_TUSERDATA);
auto *context = LuaContext::getContext(L);
Object *obj = reinterpret_cast<Object *>(luaL_checkudata(L, index, Object::className));
if (obj == nullptr) {
err(context) << "Type error, userdata is not of class " << Object::className << "\n";
luaL_typeerror(L, index, Object::className);
}
return obj;
return reinterpret_cast<Object *>(luaL_checkudata(L, index, Object::className));
}
static inline constexpr luaL_Reg luaRegDefaultGC = { "__gc", GC };
public:
static void Register(lua_State *L) noexcept
{
auto *context = LuaContext::getContext(L);
......@@ -125,6 +119,10 @@ script_class (JobDeclaration) {
static int setOptions(lua_State *) noexcept;
static int setImportFromScript(lua_State *) noexcept;
std::string name{};
std::string parentScript{};
std::vector<OptionDeclaration *> options{};
method_list metaMethods = { luaRegDefaultGC, LUA_DECL_CREATE(JobDeclaration) };
method_list methods = { LUA_DECL_METHOD(JobDeclaration, setName),
LUA_DECL_METHOD(JobDeclaration, setOptions),
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter