From 0e755ea8415774f2abbc74fc40cc1c00fcd70fe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Reuh=20Fildadut?= Date: Sat, 5 Jun 2021 17:26:02 +0200 Subject: [PATCH] Add anselme version check in game config, rename version to "game version" --- anselme.lua | 14 ++++++++++---- notes.txt | 2 -- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/anselme.lua b/anselme.lua index 0cf14c4..5b18042 100644 --- a/anselme.lua +++ b/anselme.lua @@ -203,8 +203,9 @@ local vm_mt = { -- will load in path, in order: -- * config.ans, which will be executed in the "config" namespace and may contains various optional configuration options: -- * language: string, built-in language file to load - -- * version: any, version information of the game. Can be used to perform eventual migration of save with an old version in the main file. - -- Always included in saved variables. + -- * anselme version: number, version of the anselme language this game was made for + -- * game version: any, version information of the game. Can be used to perform eventual migration of save with an old version in the main file. + -- Always included in saved variables. -- * main file: string, name (without .ans extension) of a file that will be loaded into the root namespace and ran when starting the game -- * main file, if defined in config.ans -- * every other file in the path and subdirectories, using their path as namespace (i.e., contents of path/world1/john.ans will be defined in a function world1.john) @@ -222,12 +223,17 @@ local vm_mt = { -- get config self.game = { language = self:eval("config.language"), - version = self:eval("config.version"), + anselme_version = self:eval("config.anselme version"), + game_version = self:eval("config.game version"), main_file = self:eval("config.main file"), main_block = nil } + -- check language version + if self.game.anselme_version and self.game.anselme_version ~= anselme.versions.language then + return nil, ("trying to load game made for Anselme language %s, but currently using version %s"):format(self.game.anselme_version, anselme.versions.language) + end -- force merging version into state - local interpreter, err = self:run("config.version") + local interpreter, err = self:run("config.game version") if not interpreter then return interpreter, err end interpreter:step() -- load language diff --git a/notes.txt b/notes.txt index 7c4d980..6f6ab41 100644 --- a/notes.txt +++ b/notes.txt @@ -57,5 +57,3 @@ Disadvantages: * could do something like `$ ()(l::list(?), i::number)::?`, but then can't return nil on not found... TODO: ensure that most stuff in the state stays consistent after an error was thrown - -TODO: way to migrate save files