mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 16:49:31 +00:00
Move default variables alias from game config to language file
This commit is contained in:
parent
61e3143e9e
commit
9388a22a0f
2 changed files with 18 additions and 10 deletions
23
anselme.lua
23
anselme.lua
|
|
@ -181,9 +181,6 @@ local vm_mt = {
|
||||||
-- requires LÖVE or LuaFileSystem
|
-- requires LÖVE or LuaFileSystem
|
||||||
-- will load in path, in order:
|
-- will load in path, in order:
|
||||||
-- * config.ans, which contains various optional configuration options:
|
-- * config.ans, which contains various optional configuration options:
|
||||||
-- * alias 👁️: string, default alias for 👁️
|
|
||||||
-- * alias 🏁: string, default alias for 🏁
|
|
||||||
-- * alias 🔖: string, default alias for 🔖
|
|
||||||
-- * language: string, built-in language file to load
|
-- * language: string, built-in language file to load
|
||||||
-- * main file: string, name (without .ans extension) of a file that will be loaded into the root namespace
|
-- * main file: string, name (without .ans extension) of a file that will be loaded into the root namespace
|
||||||
-- * main file, if defined in config.ans
|
-- * main file, if defined in config.ans
|
||||||
|
|
@ -196,13 +193,8 @@ local vm_mt = {
|
||||||
local s, e = self:loadfile(path.."/config.ans", "config")
|
local s, e = self:loadfile(path.."/config.ans", "config")
|
||||||
if not s then return s, e end
|
if not s then return s, e end
|
||||||
end
|
end
|
||||||
local seen_alias = self:eval("config.alias 👁️")
|
|
||||||
local checkpoint_alias = self:eval("config.alias 🔖")
|
|
||||||
local reached_alias = self:eval("config.alias 🏁")
|
|
||||||
local main_file = self:eval("config.main file")
|
local main_file = self:eval("config.main file")
|
||||||
local language = self:eval("config.language")
|
local language = self:eval("config.language")
|
||||||
-- set aliases
|
|
||||||
self:setaliases(seen_alias, checkpoint_alias, reached_alias)
|
|
||||||
-- load language
|
-- load language
|
||||||
if language then
|
if language then
|
||||||
local s, e = self:loadlanguage(language)
|
local s, e = self:loadlanguage(language)
|
||||||
|
|
@ -284,14 +276,25 @@ local vm_mt = {
|
||||||
end,
|
end,
|
||||||
|
|
||||||
--- load & execute a built-in language file
|
--- load & execute a built-in language file
|
||||||
|
-- the language file may optionally contain the special variables:
|
||||||
|
-- * alias 👁️: string, default alias for 👁️
|
||||||
|
-- * alias 🏁: string, default alias for 🏁
|
||||||
|
-- * alias 🔖: string, default alias for 🔖
|
||||||
-- return self in case of success
|
-- return self in case of success
|
||||||
-- returns nil, err in case of error
|
-- returns nil, err in case of error
|
||||||
loadlanguage = function(self, lang)
|
loadlanguage = function(self, lang)
|
||||||
|
local namespace = "anselme."..lang
|
||||||
|
-- execute language file
|
||||||
local code = require(anselme_root.."stdlib.languages."..lang)
|
local code = require(anselme_root.."stdlib.languages."..lang)
|
||||||
local s, e = self:loadstring(code, "anselme."..lang, lang)
|
local s, e = self:loadstring(code, namespace, lang)
|
||||||
if not s then return s, e end
|
if not s then return s, e end
|
||||||
s, e = self:eval("anselme."..lang)
|
s, e = self:eval(namespace)
|
||||||
if e then return s, e end
|
if e then return s, e end
|
||||||
|
-- set aliases for built-in variables
|
||||||
|
local seen_alias = self:eval(namespace..".alias 👁️")
|
||||||
|
local checkpoint_alias = self:eval(namespace..".alias 🔖")
|
||||||
|
local reached_alias = self:eval(namespace..".alias 🏁")
|
||||||
|
self:setaliases(seen_alias, checkpoint_alias, reached_alias)
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,4 +22,9 @@ return [[
|
||||||
~ "cycle".alias("cycler")
|
~ "cycle".alias("cycler")
|
||||||
~ "random".alias("aléatoire")
|
~ "random".alias("aléatoire")
|
||||||
~ "next".alias("séquence")
|
~ "next".alias("séquence")
|
||||||
|
|
||||||
|
(Built-in variables)
|
||||||
|
:alias 👁️ = "vu"
|
||||||
|
:alias 🔖 = "checkpoint"
|
||||||
|
:alias 🏁 = "atteint"
|
||||||
]]
|
]]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue