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
02f4ac7e
Vérifiée
Valider
02f4ac7e
rédigé
30 juil. 2021
par
Kubat
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
SCRIPT: Setup a custom _ENV for scripts to be executed inside + protect the Vivy table
parent
9c0e7ba6
Branches
Branches contenant la validation
Aucune étiquette associée trouvée
1 requête de fusion
!9
Lua cpp expose
Modifications
3
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
3 fichiers modifiés
src/Lib/Script/LuaContext.cc
+12
-3
12 ajouts, 3 suppressions
src/Lib/Script/LuaContext.cc
src/Lib/Script/LuaContext.hh
+1
-4
1 ajout, 4 suppressions
src/Lib/Script/LuaContext.hh
utils/rsc/lua/lib.lua
+41
-18
41 ajouts, 18 suppressions
utils/rsc/lua/lib.lua
avec
54 ajouts
et
25 suppressions
src/Lib/Script/LuaContext.cc
+
12
−
3
Voir le fichier @
02f4ac7e
...
@@ -19,7 +19,6 @@ LuaContext::LuaContext() noexcept
...
@@ -19,7 +19,6 @@ LuaContext::LuaContext() noexcept
loadString
(
libVivy
.
readAll
().
toStdString
().
c_str
());
// Load the lib
loadString
(
libVivy
.
readAll
().
toStdString
().
c_str
());
// Load the lib
SampleObject
::
Register
(
L
);
// Load the C++ objects
SampleObject
::
Register
(
L
);
// Load the C++ objects
swapEnv
();
// Swap the _ENV
}
}
LuaContext
::~
LuaContext
()
noexcept
LuaContext
::~
LuaContext
()
noexcept
...
@@ -27,6 +26,12 @@ LuaContext::~LuaContext() noexcept
...
@@ -27,6 +26,12 @@ LuaContext::~LuaContext() noexcept
lua_close
(
L
);
lua_close
(
L
);
}
}
void
LuaContext
::
swapEnv
()
noexcept
{
lua_setglobal
(
L
,
"vivy"
);
}
int
int
LuaContext
::
exec
()
noexcept
LuaContext
::
exec
()
noexcept
{
{
...
@@ -40,16 +45,20 @@ LuaContext::exec() noexcept
...
@@ -40,16 +45,20 @@ LuaContext::exec() noexcept
int
int
LuaContext
::
loadString
(
const
char
*
str
)
noexcept
LuaContext
::
loadString
(
const
char
*
str
)
noexcept
{
{
if
(
luaL_loadstring
(
L
,
str
)
!=
LUA_OK
)
if
(
luaL_loadstring
(
L
,
str
)
!=
LUA_OK
)
{
puts
(
"Error loading string"
);
return
LUA_ERRERR
;
return
LUA_ERRERR
;
}
return
exec
();
return
exec
();
}
}
int
int
LuaContext
::
loadFile
(
const
char
*
file
)
noexcept
LuaContext
::
loadFile
(
const
char
*
file
)
noexcept
{
{
if
(
luaL_loadfile
(
L
,
file
)
!=
LUA_OK
)
if
(
luaL_loadfile
(
L
,
file
)
!=
LUA_OK
)
{
puts
(
"Error loading file"
);
return
LUA_ERRERR
;
return
LUA_ERRERR
;
}
return
exec
();
return
exec
();
}
}
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/Lib/Script/LuaContext.hh
+
1
−
4
Voir le fichier @
02f4ac7e
...
@@ -28,10 +28,7 @@ private:
...
@@ -28,10 +28,7 @@ private:
int
exec
()
noexcept
;
int
exec
()
noexcept
;
// Swap the env, needed before executing a user script!
// Swap the env, needed before executing a user script!
void
swapEnv
()
noexcept
void
swapEnv
()
noexcept
;
{
loadString
(
"_ENV = vivy
\n
"
);
}
};
};
}
}
Ce diff est replié.
Cliquez pour l'agrandir.
utils/rsc/lua/lib.lua
+
41
−
18
Voir le fichier @
02f4ac7e
...
@@ -30,34 +30,46 @@ Iterable = enum {
...
@@ -30,34 +30,46 @@ Iterable = enum {
"SYLLABE"
"SYLLABE"
}
}
-- Table: reservedKeywords["keyword"] = "type"
-- Table: ReservedKeywords["keyword"] = "type"
local
reservedKeywords
=
{}
local
ReservedKeywords
=
{
[
"Vivy"
]
=
"table"
}
-- Vivy global object construction
-- Vivy global object construction
vivy
=
{}
Vivy
=
{
-- Standard libraries
[
"math"
]
=
math
,
[
"string"
]
=
string
,
[
"utf8"
]
=
utf8
,
[
"table"
]
=
table
,
-- Custom things
[
"Iterable"
]
=
Iterable
,
}
vivy
.
math
=
math
version
=
{
vivy
.
Iterable
=
Iterable
vivy
.
Vivy
=
vivy
vivy
.
Version
=
setmetatable
({
[
"MAJOR"
]
=
0
,
[
"MAJOR"
]
=
0
,
[
"MINOR"
]
=
1
,
[
"MINOR"
]
=
1
,
[
"PATCH"
]
=
0
,
[
"PATCH"
]
=
0
,
[
"LABEL"
]
=
"alpha"
,
[
"LABEL"
]
=
"alpha"
,
},
{
}
Vivy
[
"Version"
]
=
setmetatable
(
version
,
{
__tostring
=
function
()
__tostring
=
function
()
return
string.format
(
"%d.%d.%d-%s"
,
return
string.format
(
"%d.%d.%d-%s"
,
vivy
.
Version
.
MAJOR
,
Vivy
.
Version
.
MAJOR
,
vivy
.
Version
.
MINOR
,
Vivy
.
Version
.
MINOR
,
vivy
.
Version
.
PATCH
,
Vivy
.
Version
.
PATCH
,
vivy
.
Version
.
LABEL
)
Vivy
.
Version
.
LABEL
)
end
,
__newindex
=
function
(
t
,
k
,
v
)
if
reservedKeywords
[
k
]
~=
nil
then
error
(
k
..
" is a reserved word"
)
else
rawset
(
t
,
k
,
v
)
end
end
})
-- In case we are able to do the _ENV <- Vivy one day...
Vivy
[
"Vivy"
]
=
Vivy
Vivy
=
setmetatable
(
Vivy
,
{
__newindex
=
function
(
t
,
k
,
v
)
error
(
"you can't set new keys in the Vivy table"
)
end
end
})
})
...
@@ -65,3 +77,14 @@ vivy.Version = setmetatable({
...
@@ -65,3 +77,14 @@ vivy.Version = setmetatable({
io
=
nil
io
=
nil
os
=
nil
os
=
nil
debug
=
nil
debug
=
nil
local
_ENV
=
setmetatable
(
Vivy
,
{
__newindex
=
function
(
t
,
k
,
v
)
-- Use the ReservedKeywords table here
if
(
k
~=
"Vivy"
)
then
rawset
(
t
,
k
,
v
)
else
error
(
"Try to assign something to the protected global symbol 'Vivy'"
)
end
end
})
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