diff options
| author | Alexander Gavrilov | 2012-04-14 19:44:07 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-04-14 19:44:07 +0400 |
| commit | cb49c92b99a5aab3f95c811a43fe4dadc1115b99 (patch) | |
| tree | fe2a4bcfc0a11e5ef3e2cbfbc864e5b9e8aa9ceb /plugins/burrows.cpp | |
| parent | 7a34a89f53071a8368ec5bd064accb10354b6d56 (diff) | |
| download | dfhack-cb49c92b99a5aab3f95c811a43fe4dadc1115b99.tar.gz dfhack-cb49c92b99a5aab3f95c811a43fe4dadc1115b99.tar.bz2 dfhack-cb49c92b99a5aab3f95c811a43fe4dadc1115b99.tar.xz | |
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.
Diffstat (limited to 'plugins/burrows.cpp')
| -rw-r--r-- | plugins/burrows.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/plugins/burrows.cpp b/plugins/burrows.cpp index c973405e..74cb57c4 100644 --- a/plugins/burrows.cpp +++ b/plugins/burrows.cpp @@ -2,6 +2,9 @@ #include "Console.h" #include "Export.h" #include "PluginManager.h" +#include "Error.h" + +#include "DataFuncs.h" #include "modules/Gui.h" #include "modules/Job.h" @@ -420,6 +423,9 @@ static df::burrow *findByName(color_ostream &out, std::string name, bool silent static void copyUnits(df::burrow *target, df::burrow *source, bool enable) { + CHECK_NULL_POINTER(target); + CHECK_NULL_POINTER(source); + if (source == target) { if (!enable) @@ -439,6 +445,9 @@ static void copyUnits(df::burrow *target, df::burrow *source, bool enable) static void copyTiles(df::burrow *target, df::burrow *source, bool enable) { + CHECK_NULL_POINTER(target); + CHECK_NULL_POINTER(source); + if (source == target) { if (!enable) @@ -480,6 +489,8 @@ static void copyTiles(df::burrow *target, df::burrow *source, bool enable) static void setTilesByDesignation(df::burrow *target, df::tile_designation d_mask, df::tile_designation d_value, bool enable) { + CHECK_NULL_POINTER(target); + auto &blocks = world->map.map_blocks; for (size_t i = 0; i < blocks.size(); i++) @@ -512,6 +523,8 @@ static void setTilesByDesignation(df::burrow *target, df::tile_designation d_mas static bool setTilesByKeyword(df::burrow *target, std::string name, bool enable) { + CHECK_NULL_POINTER(target); + df::tile_designation mask(0); df::tile_designation value(0); @@ -538,6 +551,14 @@ static bool setTilesByKeyword(df::burrow *target, std::string name, bool enable) return true; } +DFHACK_PLUGIN_LUA_FUNCTIONS { + DFHACK_LUA_FUNCTION(findByName), + DFHACK_LUA_FUNCTION(copyUnits), + DFHACK_LUA_FUNCTION(copyTiles), + DFHACK_LUA_FUNCTION(setTilesByKeyword), + DFHACK_LUA_END +}; + static command_result burrow(color_ostream &out, vector <string> ¶meters) { CoreSuspender suspend; |
