mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-27 22:55:16 +01:00
- the scenery API (eu07.events) hands out a full userdata of its own locked metatable for each kind of object (event, track, isolated, vehicle, memcell), checked with luaL_checkudata: a handle of another kind, a light userdata or any other value is a Lua error, not an object taken for another. nil stays "no object". one object has one handle while the script holds it, so handles compare and key tables as before. event handlers get their handles built inside lua_cpcall, and nil for no activator - memcell_values keeps its text as a std::string: the text of a number was read from a stack slot popped before use - newproxy is gone from the sandboxed libraries - a config block of a scenery no longer changes what only eu07.ini sets (lua.fulllibraries, execonexit, extcam.cmd/rec, screenshotsdir, network.server/client, zmq.address, motiontelemetry, uart, feedbackmode, feedbackport, python/luascreens/wasm.enabled): kept before its keys are read, put back before FinalizeConfig(), each attempt logged - open_file_library() iterates luaL_Reg instead of a std::pair GCC 13 deduces as a pair of an array and a function
59 lines
2.3 KiB
C++
59 lines
2.3 KiB
C++
#pragma once
|
|
#include <lua.hpp>
|
|
#include <stdafx.h>
|
|
#include "scripting/luasandbox.h"
|
|
|
|
#include <string>
|
|
|
|
class basic_event;
|
|
class TMemCell;
|
|
class TDynamicObject;
|
|
struct memcell_values { std::string str; double num1; double num2; };
|
|
|
|
class lua
|
|
{
|
|
lua_State *state;
|
|
bool full_libraries = false; // lua.fulllibraries: all of LuaJIT's libraries opened
|
|
// what eu07.read_file reads (the scenery folder) and eu07.write_file writes (the scenery's data folder), known
|
|
// when the scenery loads its scripts (interpret())
|
|
lua_sandbox::file_folders files;
|
|
|
|
static int atpanic(lua_State *s);
|
|
|
|
static int scriptapi_event_create(lua_State *L);
|
|
static int scriptapi_event_find(lua_State *L);
|
|
static int scriptapi_event_exists(lua_State *L);
|
|
static int scriptapi_event_getname(lua_State *L);
|
|
static int scriptapi_event_dispatch(lua_State *L);
|
|
static int scriptapi_event_dispatch_n(lua_State *L);
|
|
static int scriptapi_track_find(lua_State *L);
|
|
static int scriptapi_track_isoccupied(lua_State *L);
|
|
static int scriptapi_track_isoccupied_n(lua_State *L);
|
|
static int scriptapi_isolated_find(lua_State *L);
|
|
static int scriptapi_isolated_isoccupied(lua_State *L);
|
|
static int scriptapi_isolated_isoccupied_n(lua_State *L);
|
|
static int scriptapi_train_getname(lua_State *L);
|
|
static int scriptapi_dynobj_putvalues(lua_State *L);
|
|
static int scriptapi_memcell_find(lua_State *L);
|
|
static int scriptapi_memcell_read(lua_State *L);
|
|
static int scriptapi_memcell_read_n(lua_State *L);
|
|
static int scriptapi_memcell_update(lua_State *L);
|
|
static int scriptapi_memcell_update_n(lua_State *L);
|
|
static int scriptapi_random(lua_State *L);
|
|
static int scriptapi_writelog(lua_State *L);
|
|
static int scriptapi_writeerrorlog(lua_State *L);
|
|
|
|
public:
|
|
lua();
|
|
~lua();
|
|
|
|
std::string get_error() const;
|
|
// runs the script file, a relative path inside folder (the scenery folder), sandboxed (scripting/luasandbox.h).
|
|
// a script that can't be read or fails is logged
|
|
void interpret(const std::string &folder, const std::string &file);
|
|
static void unref(lua_State *L, int ref);
|
|
static void dispatch_event(lua_State *L, int handler, basic_event *event, const TDynamicObject *activator);
|
|
static void push_memcell_values(lua_State *L, const TMemCell *mc);
|
|
static memcell_values get_memcell_values(lua_State *L, int idx);
|
|
};
|