summaryrefslogtreecommitdiff
path: root/plugins/lua
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-04-14 19:44:07 +0400
committerAlexander Gavrilov2012-04-14 19:44:07 +0400
commitcb49c92b99a5aab3f95c811a43fe4dadc1115b99 (patch)
treefe2a4bcfc0a11e5ef3e2cbfbc864e5b9e8aa9ceb /plugins/lua
parent7a34a89f53071a8368ec5bd064accb10354b6d56 (diff)
downloaddfhack-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/lua')
-rw-r--r--plugins/lua/burrows.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/plugins/lua/burrows.lua b/plugins/lua/burrows.lua
new file mode 100644
index 00000000..b1d51f6a
--- /dev/null
+++ b/plugins/lua/burrows.lua
@@ -0,0 +1,33 @@
+local _ENV = mkmodule('plugins.burrows')
+
+--[[
+
+ Native functions:
+
+ * findByName(name) -> burrow
+ * copyUnits(dest,src,enable)
+ * copyTiles(dest,src,enable)
+ * setTilesByKeyword(dest,kwd,enable) -> success
+
+ 'enable' selects between add and remove modes
+
+--]]
+
+clearUnits = dfhack.units.clearBurrowMembers
+
+function isBurrowUnit(burrow,unit)
+ return dfhack.units.isInBurrow(unit,burrow)
+end
+function setBurrowUnit(burrow,unit,enable)
+ return dfhack.units.setInBurrow(unit,burrow,enable)
+end
+
+clearTiles = dfhack.maps.clearBurrowTiles
+listBlocks = dfhack.maps.listBurrowBlocks
+
+isBurrowTile = dfhack.maps.isBurrowTile
+setBurrowTile = dfhack.maps.setBurrowTile
+isBlockBurrowTile = dfhack.maps.isBlockBurrowTile
+setBlockBurrowTile = dfhack.maps.setBlockBurrowTile
+
+return _ENV \ No newline at end of file