First attempt at error-resistant /cpl directive

This commit is contained in:
2026-06-08 17:47:10 -04:00
parent 53a06281fd
commit 6a230e3ab2
9 changed files with 169 additions and 203 deletions

View File

@@ -132,58 +132,31 @@ private:
public:
void init(lua_State *L);
// Update
//
// Update the database using the specified lua source code.
// Compiles these files using lua's "load" function.
//
void update(const util::LuaSourceVec &source);
// modules
//
// Returns a list of all the modules. The first item in the list
// is always the string "CORE" which represents the lua core
// functionality with all the builtins. This is then followed by
// all the lua sourcefiles in the correct order.
// modules()
//
// Returns a list of all the lua modules, in the proper order.
//
eng::vector<eng::string> modules();
// get_source
// Update
//
// Get the source code for a given module.
// Try to compile and load the specified source. Then, rebuild the
// global environment.
//
eng::string get_source(const eng::string &fn);
// rebuild_module
// If this generates any errors, puts back the old code, and rebuilds
// the global environment using the old code.
//
// Returns any error messages. If this returns empty string, it means
// there were no errors and the code was successfully update. If there
// are any error messages, it means we restored the old code as best as
// possible.
//
// To rebuild the lua environment, fetch the module list, then
// call rebuild_module on each module in turn. This will return
// an error message for the module, or empty string if no error.
//
// This is a thin wrapper around traceback_pcall. The return
// value is the return value of traceback_pcall.
//
eng::string rebuild_module(const eng::string &mod);
// rebuild_core
//
// This is equivalent to rebuild_module("CORE"). Clears the environment
// and installs all the builtins. No error conditions.
//
void rebuild_core();
// rebuild_funcnames
//
// Traverses the global environment and populates the registry "funcnames"
// table, mapping each closure to its name.
//
void rebuild_funcnames();
eng::string update(const util::LuaSourceVec &source);
// Difference transmission.
//
// Note: The patch routine applies the differences to the source
// database, and if there are any changes, it does a source rebuild.
// The patch routine returns true if anything was modified.
//
//
void diff(const SourceDB &auth, StreamBuffer *sb);
bool patch(StreamBuffer *sb, DebugCollector *dbc);
@@ -213,7 +186,54 @@ public:
// Serialize and unserialize a source vector.
//
static void serialize_source(const util::LuaSourceVec &sv, StreamBuffer *sb);
static void deserialize_source(util::LuaSourceVec *sv, StreamBuffer *sb);
static util::LuaSourceVec deserialize_source(std::string_view datapack);
private:
//////////////////////////////////////////////////////////////////////////
//
// Internal implementation stuff.
//
//////////////////////////////////////////////////////////////////////////
// rebuild
//
// Rebuild the global environment from the sourcedb:
//
// * Clears the environment
// * Installs the builtins
// * Executes all the closures in the sourcedb.
// * Regenerates the function-names table.
//
// The closures may generate errors, if so, this returns the error
// messages. Note that if there are errors, there is no automatic cleanup.
//
eng::string rebuild();
// get_source
//
// Get the source code for a given module.
//
eng::string get_source(const eng::string &fn);
// rebuild_module
//
// To rebuild the lua environment, fetch the module list, then
// call rebuild_module on each module in turn. This will return
// an error message for the module, or empty string if no error.
//
// This is a thin wrapper around traceback_pcall. The return
// value is the return value of traceback_pcall.
//
eng::string rebuild_module(const eng::string &mod);
// rebuild_funcnames
//
// Traverses the global environment and populates the registry "funcnames"
// table, mapping each closure to its name.
//
void rebuild_funcnames();
};