mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-19 00:59:18 +02:00
Refactor Lua bindings to not use FFI anymore
- Lua bindings are no longer using FFI in favor of the "classic" Lua C API. - This makes it work properly on native Linux builds. - Changed the Lua API slightly: - Removed the `api.event_preparefunc()` function because it is no longer necessary. Instead, you can pass any function you want without preparing it first. - Added an `api.event_exists()` function. Takes a single `name` argument. - Any `api.find_*()` functions return `nil` instead of an userdata representing a null pointer when the requested object is not found.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
#include <lua.hpp>
|
||||
#include <stdafx.h>
|
||||
|
||||
class basic_event;
|
||||
class TMemCell;
|
||||
class TDynamicObject;
|
||||
|
||||
class lua
|
||||
@@ -9,14 +11,39 @@ class lua
|
||||
lua_State *state;
|
||||
|
||||
static int atpanic(lua_State *s);
|
||||
static int openffi(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();
|
||||
void interpret(std::string file);
|
||||
std::string get_error() const;
|
||||
void interpret(const std::string& file) const;
|
||||
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);
|
||||
|
||||
typedef void (*eventhandler_t)(basic_event*, const TDynamicObject*);
|
||||
struct memcell_values { const char *str; double num1; double num2; };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user