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
8342cd07
Vérifiée
Valider
8342cd07
rédigé
Il y a 3 ans
par
Kubat
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
[WIP] SCRIPT: Add methods to load and export modules and functions
parent
b671c073
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
3
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
3 fichiers modifiés
src/Lib/Script/CRTPLuaScriptObject.cc
+46
-0
46 ajouts, 0 suppression
src/Lib/Script/CRTPLuaScriptObject.cc
src/Lib/Script/CRTPLuaScriptObject.hh
+10
-4
10 ajouts, 4 suppressions
src/Lib/Script/CRTPLuaScriptObject.hh
src/Lib/Script/LuaContext.cc
+1
-0
1 ajout, 0 suppression
src/Lib/Script/LuaContext.cc
avec
57 ajouts
et
4 suppressions
src/Lib/Script/CRTPLuaScriptObject.cc
+
46
−
0
Voir le fichier @
8342cd07
...
@@ -57,6 +57,52 @@ ModuleDeclaration::resolvModules(LuaContext *const context) noexcept
...
@@ -57,6 +57,52 @@ ModuleDeclaration::resolvModules(LuaContext *const context) noexcept
return
true
;
return
true
;
}
}
int
ModuleDeclaration
::
importMethod
(
lua_State
*
const
L
)
noexcept
{
auto
*
const
self
=
CHECK
(
L
,
1
);
auto
*
const
context
=
LuaContext
::
getContext
(
L
);
luaL_checktype
(
L
,
2
,
LUA_TTABLE
);
// Get the module name
lua_pushinteger
(
L
,
1
);
// Stack is { top: int, table, self }
lua_gettable
(
L
,
2
);
// Stack is { top: str, table, self }
const
std
::
string_view
mod
=
CHECK_STRING_VIEW
(
L
,
3
);
// Import a module
err
(
context
)
<<
"Importing a module..."
;
const
ModuleDeclaration
*
const
module
=
context
->
getModule
(
mod
);
if
(
module
)
{
err
(
context
)
<<
"Loaded module "
<<
module
->
moduleName
<<
"
\n
"
;
}
else
{
err
(
context
)
<<
"Failed to load module "
<<
mod
<<
"
\n
"
;
return
1
;
}
// Stack is { top: module, str, table, self }
// Import a function
if
(
lua_rawlen
(
L
,
2
)
==
2
)
{
lua_pushinteger
(
L
,
2
);
// Stack is { top: int, module, str, table, self }
lua_gettable
(
L
,
2
);
// Stack is { top: str, module, str, table, self }
const
std
::
string_view
func
=
CHECK_STRING_VIEW
(
L
,
5
);
err
(
context
)
<<
"Load function "
<<
func
<<
" but not implemented, pushing nil
\n
"
;
lua_pushnil
(
L
);
// Stack is { top: nil | function, str, module, str, table, self }
}
return
1
;
}
int
ModuleDeclaration
::
exportMethod
(
lua_State
*
const
L
)
noexcept
{
auto
*
const
self
=
CHECK
(
L
,
1
);
auto
*
const
context
=
LuaContext
::
getContext
(
L
);
const
std
::
string_view
object
=
CHECK_STRING_VIEW
(
L
,
2
);
err
(
context
)
<<
"Vivy:export: Not implemented
\n
"
;
return
0
;
}
int
int
ModuleDeclaration
::
setName
(
lua_State
*
const
L
)
noexcept
ModuleDeclaration
::
setName
(
lua_State
*
const
L
)
noexcept
{
{
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/Lib/Script/CRTPLuaScriptObject.hh
+
10
−
4
Voir le fichier @
8342cd07
...
@@ -11,6 +11,7 @@ namespace Vivy::Script
...
@@ -11,6 +11,7 @@ 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_NAMED_METHOD(class, method, name) luaL_Reg{ method, class ::name }
#define LUA_DECL_META_METHOD(class, meta, name) luaL_Reg{ meta, class ::name }
#define LUA_DECL_META_METHOD(class, meta, name) luaL_Reg{ meta, class ::name }
#define LUA_DECL_CREATE(class) luaL_Reg{ "new", class ::CREATE }
#define LUA_DECL_CREATE(class) luaL_Reg{ "new", class ::CREATE }
#define LUA_RETURN_NOTHING(L) { lua_settop(L, 0); return 0; }
#define LUA_RETURN_NOTHING(L) { lua_settop(L, 0); return 0; }
...
@@ -233,6 +234,9 @@ script_class (ModuleDeclaration) {
...
@@ -233,6 +234,9 @@ script_class (ModuleDeclaration) {
static
int
pushToRuntime
(
lua_State
*
const
)
noexcept
;
static
int
pushToRuntime
(
lua_State
*
const
)
noexcept
;
static
int
importMethod
(
lua_State
*
const
)
noexcept
;
static
int
exportMethod
(
lua_State
*
const
)
noexcept
;
method_list
metaMethods
=
{
luaRegDefaultGC
};
method_list
metaMethods
=
{
luaRegDefaultGC
};
method_list
methods
=
{
method_list
methods
=
{
LUA_DECL_METHOD
(
ModuleDeclaration
,
setName
),
LUA_DECL_METHOD
(
ModuleDeclaration
,
setName
),
...
@@ -245,6 +249,8 @@ script_class (ModuleDeclaration) {
...
@@ -245,6 +249,8 @@ script_class (ModuleDeclaration) {
LUA_DECL_METHOD
(
ModuleDeclaration
,
setFunctions
),
LUA_DECL_METHOD
(
ModuleDeclaration
,
setFunctions
),
LUA_DECL_METHOD
(
ModuleDeclaration
,
setJobs
),
LUA_DECL_METHOD
(
ModuleDeclaration
,
setJobs
),
LUA_DECL_METHOD
(
ModuleDeclaration
,
pushToRuntime
),
LUA_DECL_METHOD
(
ModuleDeclaration
,
pushToRuntime
),
LUA_DECL_NAMED_METHOD
(
ModuleDeclaration
,
"import"
,
importMethod
),
LUA_DECL_NAMED_METHOD
(
ModuleDeclaration
,
"export"
,
exportMethod
),
LUA_DECL_CREATE
(
ModuleDeclaration
),
LUA_DECL_CREATE
(
ModuleDeclaration
),
};
};
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/Lib/Script/LuaContext.cc
+
1
−
0
Voir le fichier @
8342cd07
...
@@ -168,6 +168,7 @@ LuaContext::getModule(const std::string_view name) const noexcept
...
@@ -168,6 +168,7 @@ LuaContext::getModule(const std::string_view name) const noexcept
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
r
);
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
r
);
return
ModuleDeclaration
::
CHECK
(
L
,
-
1
);
return
ModuleDeclaration
::
CHECK
(
L
,
-
1
);
}
else
{
}
else
{
lua_pushnil
(
L
);
return
nullptr
;
return
nullptr
;
}
}
}
}
...
...
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