2012-03-19 06:59:11 -06:00
|
|
|
/*
|
|
|
|
https://github.com/peterix/dfhack
|
2012-09-29 20:03:37 -06:00
|
|
|
Copyright (c) 2009-2012 Petr Mrázek (peterix@gmail.com)
|
2012-03-19 06:59:11 -06:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any
|
|
|
|
damages arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any
|
|
|
|
purpose, including commercial applications, and to alter it and
|
|
|
|
redistribute it freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must
|
|
|
|
not claim that you wrote the original software. If you use this
|
|
|
|
software in a product, an acknowledgment in the product documentation
|
|
|
|
would be appreciated but is not required.
|
|
|
|
|
|
|
|
2. Altered source versions must be plainly marked as such, and
|
|
|
|
must not be misrepresented as being the original software.
|
|
|
|
|
|
|
|
3. This notice may not be removed or altered from any source
|
|
|
|
distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-07-07 04:27:29 -06:00
|
|
|
#include <deque>
|
2023-09-12 21:37:56 -06:00
|
|
|
#include <future>
|
2023-05-28 00:50:39 -06:00
|
|
|
#include <map>
|
2023-09-12 21:37:56 -06:00
|
|
|
#include <optional>
|
2012-03-19 06:59:11 -06:00
|
|
|
#include <sstream>
|
2023-05-28 00:50:39 -06:00
|
|
|
#include <string>
|
2023-09-12 21:37:56 -06:00
|
|
|
#include <unordered_map>
|
2023-12-10 03:25:53 -07:00
|
|
|
#include <variant>
|
2012-03-19 06:59:11 -06:00
|
|
|
#include <vector>
|
2023-12-08 17:27:06 -07:00
|
|
|
#include <variant>
|
2012-03-19 06:59:11 -06:00
|
|
|
|
|
|
|
#include "DataDefs.h"
|
|
|
|
|
2023-12-10 22:30:41 -07:00
|
|
|
#include <df/widget_container.h>
|
|
|
|
|
2023-05-28 23:12:35 -06:00
|
|
|
namespace std {
|
|
|
|
class condition_variable;
|
|
|
|
class mutex;
|
|
|
|
};
|
|
|
|
|
2012-03-19 06:59:11 -06:00
|
|
|
/*
|
|
|
|
* Definitions of DFHack namespace structs used by generated headers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace DFHack
|
|
|
|
{
|
2012-03-25 04:06:05 -06:00
|
|
|
class DFHACK_EXPORT function_identity_base : public type_identity {
|
|
|
|
int num_args;
|
2012-04-15 09:09:25 -06:00
|
|
|
bool vararg;
|
2012-03-25 04:06:05 -06:00
|
|
|
|
|
|
|
public:
|
2012-04-15 09:09:25 -06:00
|
|
|
function_identity_base(int num_args, bool vararg = false)
|
|
|
|
: type_identity(0), num_args(num_args), vararg(vararg) {};
|
2012-03-25 04:06:05 -06:00
|
|
|
|
|
|
|
virtual identity_type type() { return IDTYPE_FUNCTION; }
|
|
|
|
|
|
|
|
int getNumArgs() { return num_args; }
|
2012-04-15 09:09:25 -06:00
|
|
|
bool adjustArgs() { return vararg; }
|
|
|
|
|
2012-03-25 04:06:05 -06:00
|
|
|
std::string getFullName() { return "function"; }
|
|
|
|
|
|
|
|
virtual void invoke(lua_State *state, int base) = 0;
|
|
|
|
|
|
|
|
virtual void lua_read(lua_State *state, int fname_idx, void *ptr);
|
|
|
|
virtual void lua_write(lua_State *state, int fname_idx, void *ptr, int val_index);
|
|
|
|
};
|
|
|
|
|
2012-03-19 06:59:11 -06:00
|
|
|
class DFHACK_EXPORT primitive_identity : public type_identity {
|
|
|
|
public:
|
|
|
|
primitive_identity(size_t size) : type_identity(size) {};
|
|
|
|
|
|
|
|
virtual identity_type type() { return IDTYPE_PRIMITIVE; }
|
|
|
|
};
|
|
|
|
|
2014-09-24 12:47:04 -06:00
|
|
|
class DFHACK_EXPORT opaque_identity : public constructed_identity {
|
|
|
|
std::string name;
|
|
|
|
|
|
|
|
public:
|
|
|
|
opaque_identity(size_t size, TAllocateFn alloc, const std::string &name)
|
|
|
|
: constructed_identity(size, alloc), name(name) {};
|
|
|
|
|
|
|
|
virtual std::string getFullName() { return name; }
|
|
|
|
virtual identity_type type() { return IDTYPE_OPAQUE; }
|
|
|
|
};
|
|
|
|
|
2012-03-20 03:56:29 -06:00
|
|
|
class DFHACK_EXPORT pointer_identity : public primitive_identity {
|
|
|
|
type_identity *target;
|
|
|
|
|
|
|
|
public:
|
|
|
|
pointer_identity(type_identity *target = NULL)
|
|
|
|
: primitive_identity(sizeof(void*)), target(target) {};
|
|
|
|
|
|
|
|
virtual identity_type type() { return IDTYPE_POINTER; }
|
|
|
|
|
|
|
|
type_identity *getTarget() { return target; }
|
|
|
|
|
2012-03-21 03:26:53 -06:00
|
|
|
std::string getFullName();
|
|
|
|
|
2012-03-22 23:38:49 -06:00
|
|
|
static void lua_read(lua_State *state, int fname_idx, void *ptr, type_identity *target);
|
2012-03-20 11:34:27 -06:00
|
|
|
static void lua_write(lua_State *state, int fname_idx, void *ptr, type_identity *target, int val_index);
|
|
|
|
|
2012-03-22 23:38:49 -06:00
|
|
|
virtual void lua_read(lua_State *state, int fname_idx, void *ptr);
|
2012-03-20 03:56:29 -06:00
|
|
|
virtual void lua_write(lua_State *state, int fname_idx, void *ptr, int val_index);
|
|
|
|
};
|
|
|
|
|
2012-03-19 06:59:11 -06:00
|
|
|
class DFHACK_EXPORT container_identity : public constructed_identity {
|
|
|
|
type_identity *item;
|
|
|
|
enum_identity *ienum;
|
|
|
|
|
|
|
|
public:
|
|
|
|
container_identity(size_t size, TAllocateFn alloc, type_identity *item, enum_identity *ienum = NULL)
|
|
|
|
: constructed_identity(size, alloc), item(item), ienum(ienum) {};
|
|
|
|
|
|
|
|
virtual identity_type type() { return IDTYPE_CONTAINER; }
|
2012-03-20 03:56:29 -06:00
|
|
|
|
2012-03-21 03:26:53 -06:00
|
|
|
std::string getFullName() { return getFullName(item); }
|
|
|
|
|
|
|
|
virtual void build_metatable(lua_State *state);
|
|
|
|
virtual bool isContainer() { return true; }
|
|
|
|
|
2012-03-20 03:56:29 -06:00
|
|
|
type_identity *getItemType() { return item; }
|
2012-03-21 03:26:53 -06:00
|
|
|
type_identity *getIndexEnumType() { return ienum; }
|
|
|
|
|
|
|
|
virtual std::string getFullName(type_identity *item);
|
|
|
|
|
2012-03-24 06:28:53 -06:00
|
|
|
enum CountMode {
|
|
|
|
COUNT_LEN, COUNT_READ, COUNT_WRITE
|
|
|
|
};
|
|
|
|
|
|
|
|
int lua_item_count(lua_State *state, void *ptr, CountMode cnt);
|
2012-03-21 03:26:53 -06:00
|
|
|
|
2012-03-23 02:55:29 -06:00
|
|
|
virtual void lua_item_reference(lua_State *state, int fname_idx, void *ptr, int idx);
|
2012-03-22 23:38:49 -06:00
|
|
|
virtual void lua_item_read(lua_State *state, int fname_idx, void *ptr, int idx);
|
2012-03-21 03:26:53 -06:00
|
|
|
virtual void lua_item_write(lua_State *state, int fname_idx, void *ptr, int idx, int val_index);
|
|
|
|
|
2012-08-18 04:34:20 -06:00
|
|
|
virtual bool is_readonly() { return false; }
|
|
|
|
|
2012-03-24 06:28:53 -06:00
|
|
|
virtual bool resize(void *ptr, int size) { return false; }
|
|
|
|
virtual bool erase(void *ptr, int index) { return false; }
|
|
|
|
virtual bool insert(void *ptr, int index, void *pitem) { return false; }
|
|
|
|
|
2016-07-26 21:47:53 -06:00
|
|
|
virtual bool lua_insert2(lua_State *state, int fname_idx, void *ptr, int idx, int val_index);
|
2012-03-24 06:28:53 -06:00
|
|
|
|
2012-03-21 03:26:53 -06:00
|
|
|
protected:
|
2012-03-24 06:28:53 -06:00
|
|
|
virtual int item_count(void *ptr, CountMode cnt) = 0;
|
2012-03-22 00:56:32 -06:00
|
|
|
virtual void *item_pointer(type_identity *item, void *ptr, int idx) = 0;
|
2012-03-21 03:26:53 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
class DFHACK_EXPORT ptr_container_identity : public container_identity {
|
|
|
|
public:
|
|
|
|
ptr_container_identity(size_t size, TAllocateFn alloc,
|
|
|
|
type_identity *item, enum_identity *ienum = NULL)
|
|
|
|
: container_identity(size, alloc, item, ienum) {};
|
|
|
|
|
|
|
|
virtual identity_type type() { return IDTYPE_PTR_CONTAINER; }
|
|
|
|
|
|
|
|
std::string getFullName(type_identity *item);
|
|
|
|
|
2012-03-23 02:55:29 -06:00
|
|
|
virtual void lua_item_reference(lua_State *state, int fname_idx, void *ptr, int idx);
|
2012-03-22 23:38:49 -06:00
|
|
|
virtual void lua_item_read(lua_State *state, int fname_idx, void *ptr, int idx);
|
2012-03-21 03:26:53 -06:00
|
|
|
virtual void lua_item_write(lua_State *state, int fname_idx, void *ptr, int idx, int val_index);
|
2012-03-24 06:28:53 -06:00
|
|
|
|
2016-07-26 21:47:53 -06:00
|
|
|
virtual bool lua_insert2(lua_State *state, int fname_idx, void *ptr, int idx, int val_index);
|
2012-03-21 03:26:53 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
class DFHACK_EXPORT bit_container_identity : public container_identity {
|
|
|
|
public:
|
|
|
|
bit_container_identity(size_t size, TAllocateFn alloc, enum_identity *ienum = NULL)
|
|
|
|
: container_identity(size, alloc, NULL, ienum) {};
|
|
|
|
|
|
|
|
virtual identity_type type() { return IDTYPE_BIT_CONTAINER; }
|
|
|
|
|
|
|
|
std::string getFullName(type_identity *item);
|
|
|
|
|
2012-03-23 02:55:29 -06:00
|
|
|
virtual void lua_item_reference(lua_State *state, int fname_idx, void *ptr, int idx);
|
2012-03-22 23:38:49 -06:00
|
|
|
virtual void lua_item_read(lua_State *state, int fname_idx, void *ptr, int idx);
|
2012-03-21 03:26:53 -06:00
|
|
|
virtual void lua_item_write(lua_State *state, int fname_idx, void *ptr, int idx, int val_index);
|
|
|
|
|
|
|
|
protected:
|
2012-03-22 00:56:32 -06:00
|
|
|
virtual void *item_pointer(type_identity *, void *, int) { return NULL; }
|
2012-03-21 03:26:53 -06:00
|
|
|
|
|
|
|
virtual bool get_item(void *ptr, int idx) = 0;
|
|
|
|
virtual void set_item(void *ptr, int idx, bool val) = 0;
|
2012-03-19 06:59:11 -06:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace df
|
|
|
|
{
|
2012-03-25 04:06:05 -06:00
|
|
|
using DFHack::function_identity_base;
|
2012-03-19 06:59:11 -06:00
|
|
|
using DFHack::primitive_identity;
|
2014-09-24 12:47:04 -06:00
|
|
|
using DFHack::opaque_identity;
|
2012-03-20 03:56:29 -06:00
|
|
|
using DFHack::pointer_identity;
|
2012-03-19 06:59:11 -06:00
|
|
|
using DFHack::container_identity;
|
2012-03-21 03:26:53 -06:00
|
|
|
using DFHack::ptr_container_identity;
|
|
|
|
using DFHack::bit_container_identity;
|
2012-03-19 06:59:11 -06:00
|
|
|
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
class DFHACK_EXPORT number_identity_base : public primitive_identity {
|
2012-03-21 03:26:53 -06:00
|
|
|
const char *name;
|
|
|
|
|
2012-03-20 03:56:29 -06:00
|
|
|
public:
|
2012-03-21 03:26:53 -06:00
|
|
|
number_identity_base(size_t size, const char *name)
|
|
|
|
: primitive_identity(size), name(name) {};
|
|
|
|
|
|
|
|
std::string getFullName() { return name; }
|
2012-03-20 03:56:29 -06:00
|
|
|
|
2016-07-28 14:36:02 -06:00
|
|
|
virtual void lua_read(lua_State *state, int fname_idx, void *ptr) = 0;
|
|
|
|
virtual void lua_write(lua_State *state, int fname_idx, void *ptr, int val_index) = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class DFHACK_EXPORT integer_identity_base : public number_identity_base {
|
|
|
|
public:
|
|
|
|
integer_identity_base(size_t size, const char *name)
|
|
|
|
: number_identity_base(size, name) {}
|
|
|
|
|
|
|
|
virtual void lua_read(lua_State *state, int fname_idx, void *ptr);
|
|
|
|
virtual void lua_write(lua_State *state, int fname_idx, void *ptr, int val_index);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual int64_t read(void *ptr) = 0;
|
|
|
|
virtual void write(void *ptr, int64_t val) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DFHACK_EXPORT float_identity_base : public number_identity_base {
|
|
|
|
public:
|
|
|
|
float_identity_base(size_t size, const char *name)
|
|
|
|
: number_identity_base(size, name) {}
|
|
|
|
|
2012-03-22 23:38:49 -06:00
|
|
|
virtual void lua_read(lua_State *state, int fname_idx, void *ptr);
|
2012-03-20 03:56:29 -06:00
|
|
|
virtual void lua_write(lua_State *state, int fname_idx, void *ptr, int val_index);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual double read(void *ptr) = 0;
|
|
|
|
virtual void write(void *ptr, double val) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
2016-07-28 14:36:02 -06:00
|
|
|
class integer_identity : public integer_identity_base {
|
|
|
|
public:
|
|
|
|
integer_identity(const char *name) : integer_identity_base(sizeof(T), name) {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual int64_t read(void *ptr) { return int64_t(*(T*)ptr); }
|
|
|
|
virtual void write(void *ptr, int64_t val) { *(T*)ptr = T(val); }
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
class float_identity : public float_identity_base {
|
2012-03-20 03:56:29 -06:00
|
|
|
public:
|
2016-07-28 14:36:02 -06:00
|
|
|
float_identity(const char *name) : float_identity_base(sizeof(T), name) {}
|
|
|
|
|
2012-03-20 03:56:29 -06:00
|
|
|
protected:
|
|
|
|
virtual double read(void *ptr) { return double(*(T*)ptr); }
|
|
|
|
virtual void write(void *ptr, double val) { *(T*)ptr = T(val); }
|
|
|
|
};
|
|
|
|
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
class DFHACK_EXPORT bool_identity : public primitive_identity {
|
2012-03-20 03:56:29 -06:00
|
|
|
public:
|
|
|
|
bool_identity() : primitive_identity(sizeof(bool)) {};
|
|
|
|
|
2012-03-21 03:26:53 -06:00
|
|
|
std::string getFullName() { return "bool"; }
|
|
|
|
|
2012-03-22 23:38:49 -06:00
|
|
|
virtual void lua_read(lua_State *state, int fname_idx, void *ptr);
|
2012-03-20 03:56:29 -06:00
|
|
|
virtual void lua_write(lua_State *state, int fname_idx, void *ptr, int val_index);
|
|
|
|
};
|
|
|
|
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
class DFHACK_EXPORT ptr_string_identity : public primitive_identity {
|
2012-03-25 09:12:59 -06:00
|
|
|
public:
|
|
|
|
ptr_string_identity() : primitive_identity(sizeof(char*)) {};
|
|
|
|
|
|
|
|
std::string getFullName() { return "char*"; }
|
|
|
|
|
|
|
|
virtual void lua_read(lua_State *state, int fname_idx, void *ptr);
|
|
|
|
virtual void lua_write(lua_State *state, int fname_idx, void *ptr, int val_index);
|
|
|
|
};
|
|
|
|
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
class DFHACK_EXPORT stl_string_identity : public DFHack::constructed_identity {
|
2012-03-20 03:56:29 -06:00
|
|
|
public:
|
2012-03-24 06:28:53 -06:00
|
|
|
stl_string_identity()
|
|
|
|
: constructed_identity(sizeof(std::string), &allocator_fn<std::string>)
|
|
|
|
{};
|
2012-03-20 03:56:29 -06:00
|
|
|
|
2012-03-21 03:26:53 -06:00
|
|
|
std::string getFullName() { return "string"; }
|
|
|
|
|
2012-03-24 06:28:53 -06:00
|
|
|
virtual DFHack::identity_type type() { return DFHack::IDTYPE_PRIMITIVE; }
|
|
|
|
|
|
|
|
virtual bool isPrimitive() { return true; }
|
|
|
|
|
2012-03-22 23:38:49 -06:00
|
|
|
virtual void lua_read(lua_State *state, int fname_idx, void *ptr);
|
2012-03-20 03:56:29 -06:00
|
|
|
virtual void lua_write(lua_State *state, int fname_idx, void *ptr, int val_index);
|
|
|
|
};
|
|
|
|
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
class DFHACK_EXPORT stl_ptr_vector_identity : public ptr_container_identity {
|
2012-03-20 03:56:29 -06:00
|
|
|
public:
|
2012-03-24 06:28:53 -06:00
|
|
|
typedef std::vector<void*> container;
|
|
|
|
|
2012-03-22 00:56:32 -06:00
|
|
|
/*
|
|
|
|
* This class assumes that std::vector<T*> is equivalent
|
|
|
|
* in layout and behavior to std::vector<void*> for any T.
|
|
|
|
*/
|
|
|
|
|
2012-03-20 03:56:29 -06:00
|
|
|
stl_ptr_vector_identity(type_identity *item = NULL, enum_identity *ienum = NULL)
|
2012-03-24 06:28:53 -06:00
|
|
|
: ptr_container_identity(sizeof(container),allocator_fn<container>,item, ienum)
|
2012-03-20 03:56:29 -06:00
|
|
|
{};
|
|
|
|
|
2012-03-21 03:26:53 -06:00
|
|
|
std::string getFullName(type_identity *item) {
|
|
|
|
return "vector" + ptr_container_identity::getFullName(item);
|
|
|
|
}
|
|
|
|
|
2012-03-20 03:56:29 -06:00
|
|
|
virtual DFHack::identity_type type() { return DFHack::IDTYPE_STL_PTR_VECTOR; }
|
2012-03-21 03:26:53 -06:00
|
|
|
|
2012-03-24 06:28:53 -06:00
|
|
|
virtual bool resize(void *ptr, int size) {
|
|
|
|
(*(container*)ptr).resize(size);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
virtual bool erase(void *ptr, int size) {
|
|
|
|
auto &ct = *(container*)ptr;
|
|
|
|
ct.erase(ct.begin()+size);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
virtual bool insert(void *ptr, int idx, void *item) {
|
|
|
|
auto &ct = *(container*)ptr;
|
|
|
|
ct.insert(ct.begin()+idx, item);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-21 03:26:53 -06:00
|
|
|
protected:
|
2012-03-24 06:28:53 -06:00
|
|
|
virtual int item_count(void *ptr, CountMode) {
|
2016-10-14 23:01:38 -06:00
|
|
|
return (int)((container*)ptr)->size();
|
2012-03-21 03:26:53 -06:00
|
|
|
};
|
2012-03-22 00:56:32 -06:00
|
|
|
virtual void *item_pointer(type_identity *, void *ptr, int idx) {
|
2012-03-24 06:28:53 -06:00
|
|
|
return &(*(container*)ptr)[idx];
|
2012-03-21 03:26:53 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
// Due to export issues, this stuff can only work in the main dll
|
|
|
|
#ifdef BUILD_DFHACK_LIB
|
2012-03-21 03:26:53 -06:00
|
|
|
class buffer_container_identity : public container_identity {
|
|
|
|
int size;
|
|
|
|
|
|
|
|
public:
|
|
|
|
buffer_container_identity()
|
|
|
|
: container_identity(0, NULL, NULL, NULL), size(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
buffer_container_identity(int size, type_identity *item, enum_identity *ienum = NULL)
|
2012-04-20 03:04:03 -06:00
|
|
|
: container_identity(0, NULL, item, ienum), size(size)
|
2012-03-21 03:26:53 -06:00
|
|
|
{}
|
|
|
|
|
2012-04-20 03:04:03 -06:00
|
|
|
size_t byte_size() { return getItemType()->byte_size()*size; }
|
|
|
|
|
2012-03-21 03:26:53 -06:00
|
|
|
std::string getFullName(type_identity *item);
|
2012-03-24 02:43:53 -06:00
|
|
|
int getSize() { return size; }
|
|
|
|
|
|
|
|
virtual DFHack::identity_type type() { return DFHack::IDTYPE_BUFFER; }
|
2012-03-21 03:26:53 -06:00
|
|
|
|
|
|
|
static buffer_container_identity base_instance;
|
|
|
|
|
|
|
|
protected:
|
2012-03-24 06:28:53 -06:00
|
|
|
virtual int item_count(void *ptr, CountMode) { return size; }
|
2012-03-22 00:56:32 -06:00
|
|
|
virtual void *item_pointer(type_identity *item, void *ptr, int idx) {
|
|
|
|
return ((uint8_t*)ptr) + idx * item->byte_size();
|
|
|
|
}
|
2012-03-21 03:26:53 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
class stl_container_identity : public container_identity {
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
public:
|
|
|
|
stl_container_identity(const char *name, type_identity *item, enum_identity *ienum = NULL)
|
|
|
|
: container_identity(sizeof(T), &allocator_fn<T>, item, ienum), name(name)
|
|
|
|
{}
|
|
|
|
|
|
|
|
std::string getFullName(type_identity *item) {
|
|
|
|
return name + container_identity::getFullName(item);
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:28:53 -06:00
|
|
|
virtual bool resize(void *ptr, int size) {
|
|
|
|
(*(T*)ptr).resize(size);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
virtual bool erase(void *ptr, int size) {
|
|
|
|
auto &ct = *(T*)ptr;
|
|
|
|
ct.erase(ct.begin()+size);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
virtual bool insert(void *ptr, int idx, void *item) {
|
|
|
|
auto &ct = *(T*)ptr;
|
|
|
|
ct.insert(ct.begin()+idx, *(typename T::value_type*)item);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-21 03:26:53 -06:00
|
|
|
protected:
|
2016-10-14 23:01:38 -06:00
|
|
|
virtual int item_count(void *ptr, CountMode) { return (int)((T*)ptr)->size(); }
|
2012-03-22 00:56:32 -06:00
|
|
|
virtual void *item_pointer(type_identity *item, void *ptr, int idx) {
|
|
|
|
return &(*(T*)ptr)[idx];
|
|
|
|
}
|
2012-03-21 03:26:53 -06:00
|
|
|
};
|
|
|
|
|
2012-08-18 04:34:20 -06:00
|
|
|
template<class T>
|
|
|
|
class ro_stl_container_identity : public container_identity {
|
2022-12-29 22:45:00 -07:00
|
|
|
protected:
|
2012-08-18 04:34:20 -06:00
|
|
|
const char *name;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ro_stl_container_identity(const char *name, type_identity *item, enum_identity *ienum = NULL)
|
|
|
|
: container_identity(sizeof(T), &allocator_fn<T>, item, ienum), name(name)
|
|
|
|
{}
|
|
|
|
|
|
|
|
std::string getFullName(type_identity *item) {
|
|
|
|
return name + container_identity::getFullName(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool is_readonly() { return true; }
|
|
|
|
virtual bool resize(void *ptr, int size) { return false; }
|
|
|
|
virtual bool erase(void *ptr, int size) { return false; }
|
|
|
|
virtual bool insert(void *ptr, int idx, void *item) { return false; }
|
|
|
|
|
|
|
|
protected:
|
2016-10-14 23:01:38 -06:00
|
|
|
virtual int item_count(void *ptr, CountMode) { return (int)((T*)ptr)->size(); }
|
2012-08-18 04:34:20 -06:00
|
|
|
virtual void *item_pointer(type_identity *item, void *ptr, int idx) {
|
|
|
|
auto iter = (*(T*)ptr).begin();
|
|
|
|
for (; idx > 0; idx--) ++iter;
|
|
|
|
return (void*)&*iter;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-12-29 22:45:00 -07:00
|
|
|
template<class T>
|
|
|
|
class ro_stl_assoc_container_identity : public ro_stl_container_identity<T> {
|
|
|
|
type_identity *key_identity;
|
|
|
|
type_identity *item_identity;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ro_stl_assoc_container_identity(const char *name, type_identity *key, type_identity *item)
|
|
|
|
: ro_stl_container_identity<T>(name, item),
|
|
|
|
key_identity(key),
|
|
|
|
item_identity(item)
|
|
|
|
{}
|
|
|
|
|
|
|
|
virtual std::string getFullName(type_identity*) override {
|
|
|
|
return std::string(ro_stl_assoc_container_identity<T>::name) + "<" + key_identity->getFullName() + ", " + item_identity->getFullName() + ">";
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void *item_pointer(type_identity *item, void *ptr, int idx) override {
|
|
|
|
auto iter = (*(T*)ptr).begin();
|
|
|
|
for (; idx > 0; idx--) ++iter;
|
|
|
|
return (void*)&iter->second;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-03-21 03:26:53 -06:00
|
|
|
class bit_array_identity : public bit_container_identity {
|
|
|
|
public:
|
2012-03-22 00:56:32 -06:00
|
|
|
/*
|
|
|
|
* This class assumes that BitArray<T> is equivalent
|
|
|
|
* in layout and behavior to BitArray<int> for any T.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef BitArray<int> container;
|
2012-03-21 03:26:53 -06:00
|
|
|
|
|
|
|
bit_array_identity(enum_identity *ienum = NULL)
|
|
|
|
: bit_container_identity(sizeof(container), &allocator_fn<container>, ienum)
|
|
|
|
{}
|
|
|
|
|
|
|
|
std::string getFullName(type_identity *item) {
|
2012-03-22 00:56:32 -06:00
|
|
|
return "BitArray<>";
|
2012-03-21 03:26:53 -06:00
|
|
|
}
|
|
|
|
|
2012-03-24 06:28:53 -06:00
|
|
|
virtual bool resize(void *ptr, int size) {
|
2014-04-04 12:33:05 -06:00
|
|
|
((container*)ptr)->resize((size+7)/8);
|
2012-03-24 06:28:53 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-21 03:26:53 -06:00
|
|
|
protected:
|
2012-03-24 06:28:53 -06:00
|
|
|
virtual int item_count(void *ptr, CountMode cnt) {
|
|
|
|
return cnt == COUNT_LEN ? ((container*)ptr)->size * 8 : -1;
|
|
|
|
}
|
2012-03-21 03:26:53 -06:00
|
|
|
virtual bool get_item(void *ptr, int idx) {
|
2012-03-22 00:56:32 -06:00
|
|
|
return ((container*)ptr)->is_set(idx);
|
2012-03-21 03:26:53 -06:00
|
|
|
}
|
|
|
|
virtual void set_item(void *ptr, int idx, bool val) {
|
2012-03-22 00:56:32 -06:00
|
|
|
((container*)ptr)->set(idx, val);
|
2012-03-21 03:26:53 -06:00
|
|
|
}
|
|
|
|
};
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
#endif
|
2012-03-21 03:26:53 -06:00
|
|
|
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
class DFHACK_EXPORT stl_bit_vector_identity : public bit_container_identity {
|
2012-03-21 03:26:53 -06:00
|
|
|
public:
|
|
|
|
typedef std::vector<bool> container;
|
|
|
|
|
|
|
|
stl_bit_vector_identity(enum_identity *ienum = NULL)
|
|
|
|
: bit_container_identity(sizeof(container), &allocator_fn<container>, ienum)
|
|
|
|
{}
|
|
|
|
|
|
|
|
std::string getFullName(type_identity *item) {
|
|
|
|
return "vector" + bit_container_identity::getFullName(item);
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:28:53 -06:00
|
|
|
virtual bool resize(void *ptr, int size) {
|
|
|
|
(*(container*)ptr).resize(size);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-21 03:26:53 -06:00
|
|
|
protected:
|
2012-03-24 06:28:53 -06:00
|
|
|
virtual int item_count(void *ptr, CountMode) {
|
2016-10-14 23:01:38 -06:00
|
|
|
return (int)((container*)ptr)->size();
|
2012-03-24 06:28:53 -06:00
|
|
|
}
|
2012-03-21 03:26:53 -06:00
|
|
|
virtual bool get_item(void *ptr, int idx) {
|
|
|
|
return (*(container*)ptr)[idx];
|
|
|
|
}
|
|
|
|
virtual void set_item(void *ptr, int idx, bool val) {
|
|
|
|
(*(container*)ptr)[idx] = val;
|
|
|
|
}
|
2012-03-20 03:56:29 -06:00
|
|
|
};
|
|
|
|
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
#ifdef BUILD_DFHACK_LIB
|
2012-03-25 09:12:59 -06:00
|
|
|
template<class T>
|
|
|
|
class enum_list_attr_identity : public container_identity {
|
|
|
|
public:
|
|
|
|
typedef enum_list_attr<T> container;
|
|
|
|
|
|
|
|
enum_list_attr_identity(type_identity *item)
|
|
|
|
: container_identity(sizeof(container), NULL, item, NULL)
|
|
|
|
{}
|
|
|
|
|
|
|
|
std::string getFullName(type_identity *item) {
|
|
|
|
return "enum_list_attr" + container_identity::getFullName(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual int item_count(void *ptr, CountMode cm) {
|
2016-10-14 23:01:38 -06:00
|
|
|
return cm == COUNT_WRITE ? 0 : (int)((container*)ptr)->size;
|
2012-03-25 09:12:59 -06:00
|
|
|
}
|
|
|
|
virtual void *item_pointer(type_identity *item, void *ptr, int idx) {
|
|
|
|
return (void*)&((container*)ptr)->items[idx];
|
|
|
|
}
|
|
|
|
};
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
#endif
|
2012-03-25 09:12:59 -06:00
|
|
|
|
2016-07-28 14:36:02 -06:00
|
|
|
#define NUMBER_IDENTITY_TRAITS(category, type) \
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
template<> struct DFHACK_EXPORT identity_traits<type> { \
|
2016-07-28 14:36:02 -06:00
|
|
|
static category##_identity<type> identity; \
|
|
|
|
static category##_identity_base *get() { return &identity; } \
|
|
|
|
};
|
|
|
|
|
|
|
|
#define INTEGER_IDENTITY_TRAITS(type) NUMBER_IDENTITY_TRAITS(integer, type)
|
|
|
|
#define FLOAT_IDENTITY_TRAITS(type) NUMBER_IDENTITY_TRAITS(float, type)
|
|
|
|
|
2023-08-04 19:00:29 -06:00
|
|
|
// the space after the use of "type" in OPAQUE_IDENTITY_TRAITS is _required_
|
|
|
|
// without it the macro generates a syntax error when type is a template specification
|
|
|
|
|
2023-12-08 17:27:06 -07:00
|
|
|
#define OPAQUE_IDENTITY_TRAITS(...) \
|
|
|
|
template<> struct DFHACK_EXPORT identity_traits<__VA_ARGS__ > { \
|
2023-05-28 23:09:59 -06:00
|
|
|
static opaque_identity identity; \
|
|
|
|
static opaque_identity *get() { return &identity; } \
|
|
|
|
};
|
|
|
|
|
2016-07-28 14:36:02 -06:00
|
|
|
INTEGER_IDENTITY_TRAITS(char);
|
2016-08-08 09:46:20 -06:00
|
|
|
INTEGER_IDENTITY_TRAITS(signed char);
|
|
|
|
INTEGER_IDENTITY_TRAITS(unsigned char);
|
|
|
|
INTEGER_IDENTITY_TRAITS(short);
|
|
|
|
INTEGER_IDENTITY_TRAITS(unsigned short);
|
|
|
|
INTEGER_IDENTITY_TRAITS(int);
|
|
|
|
INTEGER_IDENTITY_TRAITS(unsigned int);
|
2016-07-28 14:36:02 -06:00
|
|
|
INTEGER_IDENTITY_TRAITS(long);
|
|
|
|
INTEGER_IDENTITY_TRAITS(unsigned long);
|
2016-08-08 09:46:20 -06:00
|
|
|
INTEGER_IDENTITY_TRAITS(long long);
|
|
|
|
INTEGER_IDENTITY_TRAITS(unsigned long long);
|
2016-07-28 14:36:02 -06:00
|
|
|
FLOAT_IDENTITY_TRAITS(float);
|
|
|
|
FLOAT_IDENTITY_TRAITS(double);
|
2023-05-28 23:09:59 -06:00
|
|
|
OPAQUE_IDENTITY_TRAITS(std::condition_variable);
|
|
|
|
OPAQUE_IDENTITY_TRAITS(std::fstream);
|
|
|
|
OPAQUE_IDENTITY_TRAITS(std::mutex);
|
2023-08-04 19:00:29 -06:00
|
|
|
OPAQUE_IDENTITY_TRAITS(std::future<void>);
|
2023-09-12 20:55:55 -06:00
|
|
|
OPAQUE_IDENTITY_TRAITS(std::function<void()>);
|
2023-12-10 22:30:41 -07:00
|
|
|
OPAQUE_IDENTITY_TRAITS(std::function<bool()>);
|
|
|
|
OPAQUE_IDENTITY_TRAITS(std::function<int*()>);
|
|
|
|
OPAQUE_IDENTITY_TRAITS(std::function<std::string()>);
|
2023-12-08 17:27:06 -07:00
|
|
|
OPAQUE_IDENTITY_TRAITS(std::optional<std::function<void()> >);
|
|
|
|
OPAQUE_IDENTITY_TRAITS(std::variant<std::string, std::function<void()> >);
|
2023-12-10 22:30:41 -07:00
|
|
|
OPAQUE_IDENTITY_TRAITS(std::weak_ptr<df::widget_container>);
|
2012-03-20 03:56:29 -06:00
|
|
|
|
2023-09-13 19:57:28 -06:00
|
|
|
#ifdef BUILD_DFHACK_LIB
|
|
|
|
template<typename T>
|
|
|
|
struct DFHACK_EXPORT identity_traits<std::shared_ptr<T>> {
|
|
|
|
static opaque_identity *get() {
|
|
|
|
typedef std::shared_ptr<T> type;
|
|
|
|
static std::string name = std::string("shared_ptr<") + typeid(T).name() + ">";
|
|
|
|
static opaque_identity identity(sizeof(type), allocator_noassign_fn<type>, name);
|
|
|
|
return &identity;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
template<> struct DFHACK_EXPORT identity_traits<bool> {
|
2012-03-20 03:56:29 -06:00
|
|
|
static bool_identity identity;
|
|
|
|
static bool_identity *get() { return &identity; }
|
|
|
|
};
|
|
|
|
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
template<> struct DFHACK_EXPORT identity_traits<std::string> {
|
2012-03-20 03:56:29 -06:00
|
|
|
static stl_string_identity identity;
|
|
|
|
static stl_string_identity *get() { return &identity; }
|
|
|
|
};
|
|
|
|
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
template<> struct DFHACK_EXPORT identity_traits<char*> {
|
2012-03-25 09:12:59 -06:00
|
|
|
static ptr_string_identity identity;
|
|
|
|
static ptr_string_identity *get() { return &identity; }
|
|
|
|
};
|
|
|
|
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
template<> struct DFHACK_EXPORT identity_traits<const char*> {
|
2012-03-25 09:12:59 -06:00
|
|
|
static ptr_string_identity identity;
|
|
|
|
static ptr_string_identity *get() { return &identity; }
|
|
|
|
};
|
|
|
|
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
template<> struct DFHACK_EXPORT identity_traits<void*> {
|
2012-03-20 03:56:29 -06:00
|
|
|
static pointer_identity identity;
|
|
|
|
static pointer_identity *get() { return &identity; }
|
|
|
|
};
|
|
|
|
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
template<> struct DFHACK_EXPORT identity_traits<std::vector<void*> > {
|
2012-03-20 03:56:29 -06:00
|
|
|
static stl_ptr_vector_identity identity;
|
|
|
|
static stl_ptr_vector_identity *get() { return &identity; }
|
|
|
|
};
|
|
|
|
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
template<> struct DFHACK_EXPORT identity_traits<std::vector<bool> > {
|
2012-03-21 03:26:53 -06:00
|
|
|
static stl_bit_vector_identity identity;
|
|
|
|
static stl_bit_vector_identity *get() { return &identity; }
|
|
|
|
};
|
|
|
|
|
2012-03-20 03:56:29 -06:00
|
|
|
#undef NUMBER_IDENTITY_TRAITS
|
2016-07-28 14:36:02 -06:00
|
|
|
#undef INTEGER_IDENTITY_TRAITS
|
|
|
|
#undef FLOAT_IDENTITY_TRAITS
|
2023-05-28 23:09:59 -06:00
|
|
|
#undef OPAQUE_IDENTITY_TRAITS
|
2012-03-19 06:59:11 -06:00
|
|
|
|
|
|
|
// Container declarations
|
|
|
|
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
#ifdef BUILD_DFHACK_LIB
|
2012-03-19 06:59:11 -06:00
|
|
|
template<class Enum, class FT> struct identity_traits<enum_field<Enum,FT> > {
|
2021-03-30 14:55:06 -06:00
|
|
|
static enum_identity *get();
|
2012-03-19 06:59:11 -06:00
|
|
|
};
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
#endif
|
2012-03-19 06:59:11 -06:00
|
|
|
|
|
|
|
template<class T> struct identity_traits<T *> {
|
2012-03-20 03:56:29 -06:00
|
|
|
static pointer_identity *get();
|
2012-03-19 06:59:11 -06:00
|
|
|
};
|
|
|
|
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
#ifdef BUILD_DFHACK_LIB
|
2012-03-19 06:59:11 -06:00
|
|
|
template<class T, int sz> struct identity_traits<T [sz]> {
|
|
|
|
static container_identity *get();
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class T> struct identity_traits<std::vector<T> > {
|
|
|
|
static container_identity *get();
|
|
|
|
};
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
#endif
|
2012-03-19 06:59:11 -06:00
|
|
|
|
2012-03-20 03:56:29 -06:00
|
|
|
template<class T> struct identity_traits<std::vector<T*> > {
|
|
|
|
static stl_ptr_vector_identity *get();
|
|
|
|
};
|
|
|
|
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
#ifdef BUILD_DFHACK_LIB
|
2012-03-19 06:59:11 -06:00
|
|
|
template<class T> struct identity_traits<std::deque<T> > {
|
|
|
|
static container_identity *get();
|
|
|
|
};
|
|
|
|
|
2012-08-18 04:34:20 -06:00
|
|
|
template<class T> struct identity_traits<std::set<T> > {
|
|
|
|
static container_identity *get();
|
|
|
|
};
|
|
|
|
|
2022-12-29 22:45:00 -07:00
|
|
|
template<class KT, class T> struct identity_traits<std::map<KT, T>> {
|
|
|
|
static container_identity *get();
|
|
|
|
};
|
|
|
|
|
2023-09-12 21:37:56 -06:00
|
|
|
template<class KT, class T> struct identity_traits<std::unordered_map<KT, T>> {
|
|
|
|
static container_identity *get();
|
|
|
|
};
|
|
|
|
|
2012-03-29 12:56:06 -06:00
|
|
|
template<> struct identity_traits<BitArray<int> > {
|
|
|
|
static bit_array_identity identity;
|
|
|
|
static bit_container_identity *get() { return &identity; }
|
|
|
|
};
|
|
|
|
|
2012-03-19 06:59:11 -06:00
|
|
|
template<class T> struct identity_traits<BitArray<T> > {
|
2012-03-21 03:26:53 -06:00
|
|
|
static bit_container_identity *get();
|
2012-03-19 06:59:11 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class T> struct identity_traits<DfArray<T> > {
|
|
|
|
static container_identity *get();
|
|
|
|
};
|
|
|
|
|
2012-03-25 09:12:59 -06:00
|
|
|
template<class T> struct identity_traits<enum_list_attr<T> > {
|
|
|
|
static container_identity *get();
|
|
|
|
};
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
#endif
|
2012-03-25 09:12:59 -06:00
|
|
|
|
2012-03-19 06:59:11 -06:00
|
|
|
// Container definitions
|
|
|
|
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
#ifdef BUILD_DFHACK_LIB
|
2012-03-19 06:59:11 -06:00
|
|
|
template<class Enum, class FT>
|
2021-03-30 14:55:06 -06:00
|
|
|
inline enum_identity *identity_traits<enum_field<Enum,FT> >::get() {
|
|
|
|
static enum_identity identity(identity_traits<Enum>::get(), identity_traits<FT>::get());
|
|
|
|
return &identity;
|
2012-03-19 06:59:11 -06:00
|
|
|
}
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
#endif
|
2012-03-19 06:59:11 -06:00
|
|
|
|
|
|
|
template<class T>
|
2012-03-25 04:06:05 -06:00
|
|
|
inline pointer_identity *identity_traits<T *>::get() {
|
2012-03-20 03:56:29 -06:00
|
|
|
static pointer_identity identity(identity_traits<T>::get());
|
2012-03-19 06:59:11 -06:00
|
|
|
return &identity;
|
|
|
|
}
|
|
|
|
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
#ifdef BUILD_DFHACK_LIB
|
2012-03-19 06:59:11 -06:00
|
|
|
template<class T, int sz>
|
2012-03-25 04:06:05 -06:00
|
|
|
inline container_identity *identity_traits<T [sz]>::get() {
|
2012-03-21 03:26:53 -06:00
|
|
|
static buffer_container_identity identity(sz, identity_traits<T>::get());
|
2012-03-19 06:59:11 -06:00
|
|
|
return &identity;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
2012-03-25 04:06:05 -06:00
|
|
|
inline container_identity *identity_traits<std::vector<T> >::get() {
|
2012-03-19 06:59:11 -06:00
|
|
|
typedef std::vector<T> container;
|
2012-03-21 03:26:53 -06:00
|
|
|
static stl_container_identity<container> identity("vector", identity_traits<T>::get());
|
2012-03-19 06:59:11 -06:00
|
|
|
return &identity;
|
|
|
|
}
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
#endif
|
2012-03-19 06:59:11 -06:00
|
|
|
|
2012-03-20 03:56:29 -06:00
|
|
|
template<class T>
|
2012-03-25 04:06:05 -06:00
|
|
|
inline stl_ptr_vector_identity *identity_traits<std::vector<T*> >::get() {
|
2012-03-20 03:56:29 -06:00
|
|
|
static stl_ptr_vector_identity identity(identity_traits<T>::get());
|
|
|
|
return &identity;
|
|
|
|
}
|
|
|
|
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
#ifdef BUILD_DFHACK_LIB
|
2012-03-19 06:59:11 -06:00
|
|
|
template<class T>
|
2012-03-25 04:06:05 -06:00
|
|
|
inline container_identity *identity_traits<std::deque<T> >::get() {
|
2012-03-19 06:59:11 -06:00
|
|
|
typedef std::deque<T> container;
|
2012-03-21 03:26:53 -06:00
|
|
|
static stl_container_identity<container> identity("deque", identity_traits<T>::get());
|
2012-03-19 06:59:11 -06:00
|
|
|
return &identity;
|
|
|
|
}
|
|
|
|
|
2012-08-18 04:34:20 -06:00
|
|
|
template<class T>
|
|
|
|
inline container_identity *identity_traits<std::set<T> >::get() {
|
|
|
|
typedef std::set<T> container;
|
|
|
|
static ro_stl_container_identity<container> identity("set", identity_traits<T>::get());
|
|
|
|
return &identity;
|
|
|
|
}
|
|
|
|
|
2022-12-29 22:45:00 -07:00
|
|
|
template<class KT, class T>
|
|
|
|
inline container_identity *identity_traits<std::map<KT, T>>::get() {
|
|
|
|
typedef std::map<KT, T> container;
|
|
|
|
static ro_stl_assoc_container_identity<container> identity("map", identity_traits<KT>::get(), identity_traits<T>::get());
|
|
|
|
return &identity;
|
|
|
|
}
|
|
|
|
|
2023-09-12 21:37:56 -06:00
|
|
|
template<class KT, class T>
|
|
|
|
inline container_identity *identity_traits<std::unordered_map<KT, T>>::get() {
|
|
|
|
typedef std::unordered_map<KT, T> container;
|
|
|
|
static ro_stl_assoc_container_identity<container> identity("unordered_map", identity_traits<KT>::get(), identity_traits<T>::get());
|
|
|
|
return &identity;
|
|
|
|
}
|
|
|
|
|
2012-03-19 06:59:11 -06:00
|
|
|
template<class T>
|
2012-03-25 04:06:05 -06:00
|
|
|
inline bit_container_identity *identity_traits<BitArray<T> >::get() {
|
2012-03-29 12:56:06 -06:00
|
|
|
static bit_array_identity identity(identity_traits<T>::get());
|
2012-03-19 06:59:11 -06:00
|
|
|
return &identity;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
2012-03-25 04:06:05 -06:00
|
|
|
inline container_identity *identity_traits<DfArray<T> >::get() {
|
2012-03-19 06:59:11 -06:00
|
|
|
typedef DfArray<T> container;
|
2012-03-21 03:26:53 -06:00
|
|
|
static stl_container_identity<container> identity("DfArray", identity_traits<T>::get());
|
2012-03-19 06:59:11 -06:00
|
|
|
return &identity;
|
|
|
|
}
|
2012-03-25 09:12:59 -06:00
|
|
|
|
|
|
|
template<class T>
|
|
|
|
inline container_identity *identity_traits<enum_list_attr<T> >::get() {
|
|
|
|
static enum_list_attr_identity<T> identity(identity_traits<T>::get());
|
|
|
|
return &identity;
|
|
|
|
}
|
2012-04-05 01:32:23 -06:00
|
|
|
#endif
|
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
2012-04-14 09:44:07 -06:00
|
|
|
}
|