Lua: Persistent variables

Add a way for the lua scripts to set and retrieve variables
that are persistent - saved and restored with the game.

Invalidates saves.
This commit is contained in:
Pasi Kallinen
2023-01-15 10:32:31 +02:00
parent 18cc99150a
commit 6abb12aee0
8 changed files with 194 additions and 1 deletions

View File

@@ -4,6 +4,15 @@
-- This file contains lua code used by NetHack core.
-- Is it loaded once, at game start, and kept in memory until game exit.
-- Data in nh_lua_variables table can be set and queried with nh.variable()
-- This table is saved and restored along with the game.
nh_lua_variables = {
};
-- wrapper to simplify calling from nethack core
function get_variables_string()
return "nh_lua_variables=" .. table_stringify(nh_lua_variables) .. ";";
end
-- This is an example of generating an external file during gameplay,
-- which is updated periodically.