Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
Vivy
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Wiki externe
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté GitLab
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Elliu
Vivy
Validations
74b12bc7
Vérifiée
Valider
74b12bc7
rédigé
Il y a 4 ans
par
Kubat
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
SCRIPT: Change the macro to have less to write
parent
4a12875a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion
!9
Lua cpp expose
Modifications
2
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
.clang-format
+2
-5
2 ajouts, 5 suppressions
.clang-format
src/Lib/Script/CRTPLuaScriptObject.hh
+19
-18
19 ajouts, 18 suppressions
src/Lib/Script/CRTPLuaScriptObject.hh
avec
21 ajouts
et
23 suppressions
.clang-format
+
2
−
5
Voir le fichier @
74b12bc7
...
@@ -58,12 +58,9 @@ CommentPragmas: '^ KEEP pragma:'
...
@@ -58,12 +58,9 @@ CommentPragmas: '^ KEEP pragma:'
ForEachMacros:
ForEachMacros:
- 'for_each'
- 'for_each'
- 'FOR_EACH'
- 'for_ever'
- 'FOR_EVER'
- 'FOR_EVER_IF'
- 'FOR_EVER_UNTIL'
- 'FOR_EACH_FLAT_LIST_ITEM'
- 'parallel_for'
- 'parallel_for'
- 'script_class'
IncludeCategories:
IncludeCategories:
- Regex: '.*'
- Regex: '.*'
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/Lib/Script/CRTPLuaScriptObject.hh
+
19
−
18
Voir le fichier @
74b12bc7
...
@@ -11,15 +11,15 @@ namespace Vivy::Script
...
@@ -11,15 +11,15 @@ namespace Vivy::Script
// clang-format off
// clang-format off
#define LUA_DECL_METHOD(class, name) luaL_Reg{ #name, class ::name }
#define LUA_DECL_METHOD(class, name) luaL_Reg{ #name, class ::name }
#define LUA_DECL_CREATE(class) luaL_Reg{ "new", class ::CREATE }
#define LUA_DECL_CREATE(class) luaL_Reg{ "new", class ::CREATE }
#define LUA_DECL_SCRIPTABLE_CLASS(class) public CRTPLuaScriptObject<class>
#define LUA_SCRIPTABLE_CLASS(class) \
#define script_class(theClassName) \
static constexpr char className[] = #class; \
class theClassName final : public CRTPLuaScriptObject<theClassName>
friend CRTPLuaScriptObject<class>;
// clang-format on
// Simple type to hold table with methods for Lua's metatable and methodtable
#define LUA_SCRIPTABLE_CLASS(theClassName) \
using
LuaMethodTable
=
const
std
::
vector
<
luaL_Reg
>
;
VIVY_UNMOVABLE_OBJECT(theClassName) \
static constexpr char className[] = #theClassName; \
friend CRTPLuaScriptObject<theClassName>;
// clang-format on
// CRTP to expose objects to Lua
// CRTP to expose objects to Lua
template
<
class
Object
>
class
CRTPLuaScriptObject
{
template
<
class
Object
>
class
CRTPLuaScriptObject
{
...
@@ -60,12 +60,12 @@ public:
...
@@ -60,12 +60,12 @@ public:
{
{
// Fill the method table, newclass = {}
// Fill the method table, newclass = {}
lua_newtable
(
L
);
lua_newtable
(
L
);
int
methodtable
=
lua_gettop
(
L
);
const
int
methodtable
=
lua_gettop
(
L
);
// Fill the meta-table, metatable = {}
// Fill the meta-table, metatable = {}
{
{
luaL_newmetatable
(
L
,
Object
::
className
);
luaL_newmetatable
(
L
,
Object
::
className
);
int
metatable
=
lua_gettop
(
L
);
const
int
metatable
=
lua_gettop
(
L
);
lua_pushliteral
(
L
,
"__metatable"
);
lua_pushliteral
(
L
,
"__metatable"
);
lua_pushvalue
(
L
,
methodtable
);
lua_pushvalue
(
L
,
methodtable
);
...
@@ -75,7 +75,7 @@ public:
...
@@ -75,7 +75,7 @@ public:
lua_pushvalue
(
L
,
methodtable
);
lua_pushvalue
(
L
,
methodtable
);
lua_settable
(
L
,
metatable
);
lua_settable
(
L
,
metatable
);
for
(
const
luaL_Reg
meta
:
Object
::
metaMethods
)
{
for
(
const
luaL_Reg
&
meta
:
Object
::
metaMethods
)
{
fprintf
(
stderr
,
"REGISTER %s
\n
"
,
meta
.
name
);
fprintf
(
stderr
,
"REGISTER %s
\n
"
,
meta
.
name
);
lua_pushstring
(
L
,
meta
.
name
);
lua_pushstring
(
L
,
meta
.
name
);
lua_pushcfunction
(
L
,
meta
.
func
);
lua_pushcfunction
(
L
,
meta
.
func
);
...
@@ -86,7 +86,7 @@ public:
...
@@ -86,7 +86,7 @@ public:
}
}
// Fill the method table with specified methods
// Fill the method table with specified methods
for
(
const
luaL_Reg
method
:
Object
::
methods
)
{
for
(
const
luaL_Reg
&
method
:
Object
::
methods
)
{
fprintf
(
stderr
,
"REGISTER %s
\n
"
,
method
.
name
);
fprintf
(
stderr
,
"REGISTER %s
\n
"
,
method
.
name
);
lua_pushstring
(
L
,
method
.
name
);
lua_pushstring
(
L
,
method
.
name
);
lua_pushcfunction
(
L
,
method
.
func
);
lua_pushcfunction
(
L
,
method
.
func
);
...
@@ -100,17 +100,18 @@ public:
...
@@ -100,17 +100,18 @@ public:
};
};
// Default sample exposer for lua scripts
// Default sample exposer for lua scripts
class
SampleObject
final
:
LUA_DECL_SCRIPTABLE_CLASS
(
SampleObject
)
{
script_class
(
SampleObject
)
{
VIVY_UNMOVABLE_OBJECT
(
SampleO
bject
)
// Specify that it's a Lua o
bject
LUA_SCRIPTABLE_CLASS
(
SampleObject
)
LUA_SCRIPTABLE_CLASS
(
SampleObject
)
public:
// CTors and DTors
SampleObject
()
noexcept
;
SampleObject
()
noexcept
;
~
SampleObject
()
noexcept
;
~
SampleObject
()
noexcept
;
// The methods must be static with Lua interface
static
int
foo
(
lua_State
*
L
)
noexcept
;
static
int
foo
(
lua_State
*
L
)
noexcept
;
private:
// Meta and method tables, Lua specific thing
static
constexpr
inline
auto
metaMethods
=
{
luaRegDefaultGC
,
LUA_DECL_CREATE
(
SampleObject
)
};
static
constexpr
inline
auto
metaMethods
=
{
luaRegDefaultGC
,
LUA_DECL_CREATE
(
SampleObject
)
};
static
constexpr
inline
auto
methods
=
{
LUA_DECL_METHOD
(
SampleObject
,
foo
)
};
static
constexpr
inline
auto
methods
=
{
LUA_DECL_METHOD
(
SampleObject
,
foo
)
};
};
};
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter