#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <unordered_set>
#include <unordered_map>
#include "c_packer.h"
#include "c_internal.h"
#include "log.h"
#include "debug.h"
#include "threading/mutex_auto_lock.h"
#include "common/c_types.h"
#include <lauxlib.h>
Functions | |
static int | absidx (lua_State *L, int idx) |
static bool | uses_sdata (int type) |
static bool | uses_union (int type) |
static bool | can_set_into (int ktype, int vtype) |
static bool | suitable_key (lua_State *L, int idx) |
static bool | get_known_lua_metatables (lua_State *L) |
Push core.known_metatables to the stack if it exists. | |
static auto | emplace (PackedValue &pv, s16 type) |
Append instruction to end. | |
void | script_register_packer (lua_State *L, const char *regname, PackInFunc fin, PackOutFunc fout) |
static bool | find_packer (const char *regname, PackerTuple &out) |
Find a packer for a metatable. | |
static bool | find_packer (lua_State *L, int idx, PackerTuple &out) |
Find a packer matching the metatable of the Lua value. | |
static VectorRef< PackedInstr > | record_object (lua_State *L, int idx, PackedValue &pv, std::unordered_map< const void *, s32 > &seen) |
Keeps track of seen objects, which is needed to make circular references work. | |
static VectorRef< PackedInstr > | pack_inner (lua_State *L, int idx, int vidx, PackedValue &pv, std::unordered_map< const void *, s32 > &seen) |
Pack a single Lua value and add it to the instruction stream. | |
PackedValue * | script_pack (lua_State *L, int idx) |
void | script_unpack (lua_State *L, PackedValue *pv) |
void | script_dump_packed (const PackedValue *val) |
Variables | |
static std::unordered_map< std::string, Packer > | g_packers |
static std::mutex | g_packers_lock |
|
inlinestatic |
References idx.
Referenced by pack_inner(), and script_pack().
|
inlinestatic |
References uses_sdata(), and uses_union().
Referenced by pack_inner().
|
inlinestatic |
Append instruction to end.
pv | target |
type | instruction type |
References PackedValue::i, and INSTR_POP.
Referenced by pack_inner(), and record_object().
|
static |
Find a packer for a metatable.
regname | metatable name |
out | packer will be placed here |
References g_packers, and g_packers_lock.
Referenced by PackedValue::~PackedValue(), find_packer(), pack_inner(), and script_unpack().
|
static |
Find a packer matching the metatable of the Lua value.
L | Lua state |
idx | Index on stack |
out | packer will be placed here |
References CUSTOM_RIDX_METATABLE_MAP, FATAL_ERROR_IF, find_packer(), and idx.
|
inlinestatic |
Push core.known_metatables to the stack if it exists.
L | Lua state |
Referenced by pack_inner(), and script_unpack().
|
static |
Pack a single Lua value and add it to the instruction stream.
L | Lua state |
idx | Index of value on Lua stack. Must be positive, use absidx if not! |
vidx | Next free index on the stack as it would look during unpacking. (v = virtual) |
pv | target |
seen | Map of seen objects (see record_object) |
References absidx(), call_string_dump(), can_set_into(), PackedValue::contains_userdata, emplace(), find_packer(), get_known_lua_metatables(), idx, INSTR_POP, INSTR_SETMETATABLE, INSTR_SETTABLE, pack_inner(), record_object(), and suitable_key().
Referenced by pack_inner(), and script_pack().
|
static |
Keeps track of seen objects, which is needed to make circular references work.
The first time an object is seen it remembers the instruction index. The caller is expected to add instructions that produce the value immediately after. For second, third, ... calls it pushes an instruction that references the already created value.
L | Lua state |
idx | Index of value on Lua stack |
pv | target |
seen | Map of seen objects |
References emplace(), PackedValue::i, idx, INSTR_PUSHREF, and S32_MAX.
Referenced by pack_inner().
void script_dump_packed | ( | const PackedValue * | val | ) |
References FATAL_ERROR, PackedValue::i, INSTR_POP, INSTR_PUSHREF, INSTR_SETMETATABLE, INSTR_SETTABLE, and uses_sdata().
Referenced by ModApiServer::l_serialize_roundtrip().
PackedValue * script_pack | ( | lua_State * | L, |
int | idx ) |
References absidx(), idx, and pack_inner().
Referenced by ModApiServer::l_do_async_callback(), ModApiServer::l_serialize_roundtrip(), read_pv(), AsyncWorkerThread::run(), and ServerScripting::saveGlobals().
void script_register_packer | ( | lua_State * | L, |
const char * | regname, | ||
PackInFunc | fin, | ||
PackOutFunc | fout ) |
References CUSTOM_RIDX_METATABLE_MAP, FATAL_ERROR_IF, g_packers, and g_packers_lock.
Referenced by LuaItemStack::Register(), LuaPerlinNoise::Register(), LuaPerlinNoiseMap::Register(), and LuaVoxelManip::Register().
void script_unpack | ( | lua_State * | L, |
PackedValue * | pv ) |
References PackedValue::contains_userdata, find_packer(), get_known_lua_metatables(), PackedValue::i, INSTR_POP, INSTR_PUSHREF, INSTR_SETMETATABLE, INSTR_SETTABLE, sanity_check, and uses_sdata().
Referenced by EmergeScripting::EmergeScripting(), ServerScripting::InitializeAsync(), ModApiIPC::l_ipc_cas(), ModApiIPC::l_ipc_get(), ModApiServer::l_serialize_roundtrip(), AsyncWorkerThread::run(), and AsyncEngine::stepJobResults().
|
inlinestatic |
References idx, S32_MAX, and S32_MIN.
Referenced by pack_inner().
|
inlinestatic |
Referenced by can_set_into(), script_dump_packed(), and script_unpack().
|
inlinestatic |
|
static |
Referenced by find_packer(), and script_register_packer().
|
static |
Referenced by find_packer(), and script_register_packer().