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

SCRIPT: Use an iterable thing to get sub-class' methods and meta methods and...

SCRIPT: Use an iterable thing to get sub-class' methods and meta methods and not a function call that makes a copy of something
parent 60222dc0
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!9Lua cpp expose
......@@ -22,15 +22,3 @@ SampleObject::foo(lua_State *L) noexcept
fprintf(stderr, "SampleObject(%p)::foo -> %f\n", static_cast<void *>(obj), bar);
return 0;
}
LuaMethodTable
SampleObject::getMetaMethods() noexcept
{
return { luaRegDefaultGC, LUA_DECL_CREATE(SampleObject) };
}
LuaMethodTable
SampleObject::getMethods() noexcept
{
return { LUA_DECL_METHOD(SampleObject, foo) };
}
......@@ -15,9 +15,7 @@ namespace Vivy::Script
#define LUA_SCRIPTABLE_CLASS(class) \
static constexpr char className[] = #class; \
friend CRTPLuaScriptObject<class>; \
static LuaMethodTable getMetaMethods() noexcept; \
static LuaMethodTable getMethods() noexcept; \
friend CRTPLuaScriptObject<class>;
// clang-format on
// Simple type to hold table with methods for Lua's metatable and methodtable
......@@ -77,7 +75,7 @@ public:
lua_pushvalue(L, methodtable);
lua_settable(L, metatable);
for (const luaL_Reg meta : Object::getMetaMethods()) {
for (const luaL_Reg meta : Object::metaMethods) {
fprintf(stderr, "REGISTER %s\n", meta.name);
lua_pushstring(L, meta.name);
lua_pushcfunction(L, meta.func);
......@@ -88,7 +86,7 @@ public:
}
// Fill the method table with specified methods
for (const luaL_Reg method : Object::getMethods()) {
for (const luaL_Reg method : Object::methods) {
fprintf(stderr, "REGISTER %s\n", method.name);
lua_pushstring(L, method.name);
lua_pushcfunction(L, method.func);
......@@ -111,5 +109,9 @@ public:
~SampleObject() noexcept;
static int foo(lua_State *L) noexcept;
private:
static constexpr inline auto metaMethods = { luaRegDefaultGC, LUA_DECL_CREATE(SampleObject) };
static constexpr inline auto methods = { LUA_DECL_METHOD(SampleObject, foo) };
};
}
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