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
26bbe15f
Vérifiée
Valider
26bbe15f
rédigé
Il y a 3 ans
par
Kubat
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
SCRIPT: The module validation aborts the lua interpreter on errors
parent
b8b925e0
Branches
Branches contenant la validation
Aucune étiquette associée trouvée
1 requête de fusion
!16
Add a way to execute a Lua file with Vivy in a click-click way
Modifications
2
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
src/Lib/Script/CRTPLuaScriptObject.hh
+7
-0
7 ajouts, 0 suppression
src/Lib/Script/CRTPLuaScriptObject.hh
src/Lib/Script/CRTPLuaScriptObject/ModuleDeclaration.cc
+12
-26
12 ajouts, 26 suppressions
src/Lib/Script/CRTPLuaScriptObject/ModuleDeclaration.cc
avec
19 ajouts
et
26 suppressions
src/Lib/Script/CRTPLuaScriptObject.hh
+
7
−
0
Voir le fichier @
26bbe15f
...
@@ -48,6 +48,13 @@ getJobIteratorTypeFromString(const std::string_view it) noexcept
...
@@ -48,6 +48,13 @@ getJobIteratorTypeFromString(const std::string_view it) noexcept
// CRTP to expose objects to Lua
// CRTP to expose objects to Lua
template
<
class
Object
>
class
CRTPLuaScriptObject
{
template
<
class
Object
>
class
CRTPLuaScriptObject
{
protected:
protected:
static
void
_Noreturn
luaGlobalError
(
lua_State
*
const
L
,
const
std
::
string
&
str
)
noexcept
{
const
auto
*
const
context
=
LuaContext
::
getContext
(
L
);
lua_pushfstring
(
L
,
"%s:0:%s"
,
context
->
getCurrentLuaFile
().
c_str
(),
str
.
c_str
());
lua_error
(
L
);
}
static
bool
PushFunctionFromRegistry
(
lua_State
*
const
L
,
const
int
key
)
noexcept
static
bool
PushFunctionFromRegistry
(
lua_State
*
const
L
,
const
int
key
)
noexcept
{
{
if
(
key
>=
0
)
{
if
(
key
>=
0
)
{
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/Lib/Script/CRTPLuaScriptObject/ModuleDeclaration.cc
+
12
−
26
Voir le fichier @
26bbe15f
...
@@ -50,8 +50,6 @@ ModuleDeclaration::importMethod(lua_State *const L) noexcept
...
@@ -50,8 +50,6 @@ ModuleDeclaration::importMethod(lua_State *const L) noexcept
return
1
;
return
1
;
}
}
#include
<iostream>
int
int
ModuleDeclaration
::
exportMethod
(
lua_State
*
const
L
)
noexcept
ModuleDeclaration
::
exportMethod
(
lua_State
*
const
L
)
noexcept
{
{
...
@@ -204,16 +202,13 @@ ModuleDeclaration::pushToRuntime(lua_State *const L) noexcept
...
@@ -204,16 +202,13 @@ ModuleDeclaration::pushToRuntime(lua_State *const L) noexcept
self
->
importNames
.
emplace_back
(
self
->
moduleName
);
// You can use localy defined things
self
->
importNames
.
emplace_back
(
self
->
moduleName
);
// You can use localy defined things
Utils
::
uniqAndSort
<
std
::
string
>
(
self
->
importNames
);
// Better for all std algorithms
Utils
::
uniqAndSort
<
std
::
string
>
(
self
->
importNames
);
// Better for all std algorithms
if
(
self
->
validateModule
(
L
))
{
self
->
validateModule
(
L
);
// May abort the LUA context
err
(
context
)
<<
"Register module
\"
"
<<
self
->
moduleName
<<
"
\"
in the runtime!
\n
"
;
err
(
context
)
<<
"Register module
\"
"
<<
self
->
moduleName
<<
"
\"
in the runtime!
\n
"
;
lua_settop
(
L
,
1
);
lua_settop
(
L
,
1
);
if
(
context
->
registerDeclaration
(
self
)
==
LuaContext
::
Code
::
Error
)
if
(
context
->
registerDeclaration
(
self
)
==
LuaContext
::
Code
::
Error
)
context
->
setFailed
(
"Failed to register module "
+
self
->
moduleName
);
context
->
setFailed
(
"Failed to register module "
+
self
->
moduleName
);
}
else
context
->
setFailed
(
"Module "
+
self
->
moduleName
+
" is invalid"
);
// TODO: Import needed modules here!
// TODO: Import needed modules here!
const
std
::
string_view
importNeededModulesHere
=
"Import needed modules here!"
;
const
std
::
string_view
importNeededModulesHere
=
"Import needed modules here!"
;
...
@@ -221,16 +216,12 @@ ModuleDeclaration::pushToRuntime(lua_State *const L) noexcept
...
@@ -221,16 +216,12 @@ ModuleDeclaration::pushToRuntime(lua_State *const L) noexcept
LUA_RETURN_NOTHING
(
L
);
LUA_RETURN_NOTHING
(
L
);
}
}
bool
void
ModuleDeclaration
::
validateModule
(
lua_State
*
const
L
)
const
noexcept
ModuleDeclaration
::
validateModule
(
lua_State
*
const
L
)
const
noexcept
{
{
auto
*
const
context
=
LuaContext
::
getContext
(
L
);
// Minimal module file
// Minimal module file
if
(
moduleName
.
empty
()
||
authorName
.
empty
())
{
if
(
moduleName
.
empty
()
||
authorName
.
empty
())
context
->
setFailed
(
"The module does not have the minimal required information"
);
luaGlobalError
(
L
,
"The module does not have the minimal required information"
);
return
false
;
}
// Imports
// Imports
{
{
...
@@ -250,20 +241,15 @@ ModuleDeclaration::validateModule(lua_State *const L) const noexcept
...
@@ -250,20 +241,15 @@ ModuleDeclaration::validateModule(lua_State *const L) const noexcept
Utils
::
sortedSetDifference
(
usedImports
,
importNames
);
Utils
::
sortedSetDifference
(
usedImports
,
importNames
);
if
(
!
unusedImports
.
empty
())
{
if
(
!
unusedImports
.
empty
())
{
std
::
string
listStrImports
=
""
;
std
::
size_t
stringSize
=
0
;
std
::
size_t
stringSize
=
0
;
std
::
string
listStrImports
=
"There are imported modules that are used withour begin declared:"
;
for
(
const
auto
&
str
:
unusedImports
)
for
(
const
auto
&
str
:
unusedImports
)
stringSize
+=
1
+
str
.
size
();
stringSize
+=
1
+
str
.
size
();
listStrImports
.
reserve
(
stringSize
);
listStrImports
.
reserve
(
stringSize
);
for
(
const
auto
&
str
:
unusedImports
)
for
(
const
auto
&
str
:
unusedImports
)
listStrImports
+=
" "
+
str
;
listStrImports
+=
" "
+
str
;
luaGlobalError
(
L
,
listStrImports
);
context
->
setFailed
(
"There are imported modules that are "
"used without being declared:"
+
listStrImports
+
"
\n
"
);
return
false
;
}
}
}
}
return
true
;
}
}
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