@@ -350,6 +350,11 @@ <h1 class="title">DFHack Lua API</h1>
350350</ li >
351351</ ul >
352352</ li >
353+ < li > < a class ="reference internal " href ="#plugins " id ="id21 "> Plugins</ a > < ul >
354+ < li > < a class ="reference internal " href ="#burrows " id ="id22 "> burrows</ a > </ li >
355+ < li > < a class ="reference internal " href ="#sort " id ="id23 "> sort</ a > </ li >
356+ </ ul >
357+ </ li >
353358</ ul >
354359</ div >
355360< div class ="section " id ="df-structure-wrapper ">
@@ -842,37 +847,40 @@ <h2><a class="toc-backref" href="#id12">Material info lookup</a></h2>
842847</ div >
843848< div class ="section " id ="c-function-wrappers ">
844849< h2 > < a class ="toc-backref " href ="#id13 "> C++ function wrappers</ a > </ h2 >
845- < p > Thin wrappers around C++ functions, similar to the ones for virtual methods.</ p >
850+ < p > Thin wrappers around C++ functions, similar to the ones for virtual methods.
851+ One notable difference is that these explicit wrappers allow argument count
852+ adjustment according to the usual lua rules, so trailing false/nil arguments
853+ can be omitted.</ p >
846854< ul >
847- < li > < p class ="first "> < tt class ="docutils literal "> dfhack.TranslateName(name,in_english,only_last_name) </ tt > </ p >
855+ < li > < p class ="first "> < tt class ="docutils literal "> < span class =" pre " > dfhack.TranslateName(name[ ,in_english,only_last_name]) </ span > </ tt > </ p >
848856< p > Convert a language_name or only the last name part to string.</ p >
849857</ li >
850858</ ul >
851859< div class ="section " id ="gui-module ">
852860< h3 > < a class ="toc-backref " href ="#id14 "> Gui module</ a > </ h3 >
853861< ul >
854- < li > < p class ="first "> < tt class ="docutils literal "> dfhack.gui.getSelectedWorkshopJob(silent) </ tt > </ p >
862+ < li > < p class ="first "> < tt class ="docutils literal "> < span class =" pre " > dfhack.gui.getSelectedWorkshopJob([ silent]) </ span > </ tt > </ p >
855863< p > When a job is selected in < em > 'q'</ em > mode, returns the job, else
856864prints error unless silent and returns < em > nil</ em > .</ p >
857865</ li >
858- < li > < p class ="first "> < tt class ="docutils literal "> dfhack.gui.getSelectedJob(silent) </ tt > </ p >
866+ < li > < p class ="first "> < tt class ="docutils literal "> < span class =" pre " > dfhack.gui.getSelectedJob([ silent]) </ span > </ tt > </ p >
859867< p > Returns the job selected in a workshop or unit/jobs screen.</ p >
860868</ li >
861- < li > < p class ="first "> < tt class ="docutils literal "> dfhack.gui.getSelectedUnit(silent) </ tt > </ p >
869+ < li > < p class ="first "> < tt class ="docutils literal "> < span class =" pre " > dfhack.gui.getSelectedUnit([ silent]) </ span > </ tt > </ p >
862870< p > Returns the unit selected via < em > 'v'</ em > , < em > 'k'</ em > , unit/jobs, or
863871a full-screen item view of a cage or suchlike.</ p >
864872</ li >
865- < li > < p class ="first "> < tt class ="docutils literal "> dfhack.gui.getSelectedItem(silent) </ tt > </ p >
873+ < li > < p class ="first "> < tt class ="docutils literal "> < span class =" pre " > dfhack.gui.getSelectedItem([ silent]) </ span > </ tt > </ p >
866874< p > Returns the item selected via < em > 'v'</ em > ->inventory, < em > 'k'</ em > , < em > 't'</ em > , or
867875a full-screen item view of a container. Note that in the
868876last case, the highlighted < em > contained item</ em > is returned, not
869877the container itself.</ p >
870878</ li >
871- < li > < p class ="first "> < tt class ="docutils literal "> dfhack.gui.showAnnouncement(text,color,is_bright) </ tt > </ p >
879+ < li > < p class ="first "> < tt class ="docutils literal "> < span class =" pre " > dfhack.gui.showAnnouncement(text,color[ ,is_bright]) </ span > </ tt > </ p >
872880< p > Adds a regular announcement with given text, color, and brightness.
873881The is_bright boolean actually seems to invert the brightness.</ p >
874882</ li >
875- < li > < p class ="first "> < tt class ="docutils literal "> dfhack.gui.showPopupAnnouncement(text,color,is_bright) </ tt > </ p >
883+ < li > < p class ="first "> < tt class ="docutils literal "> < span class =" pre " > dfhack.gui.showPopupAnnouncement(text,color[ ,is_bright]) </ span > </ tt > </ p >
876884< p > Pops up a titan-style modal announcement window.</ p >
877885</ li >
878886</ ul >
@@ -923,6 +931,9 @@ <h3><a class="toc-backref" href="#id16">Units module</a></h3>
923931< li > < p class ="first "> < tt class ="docutils literal "> dfhack.units.getVisibleName(unit)</ tt > </ p >
924932< p > Returns the language_name object visible in game, accounting for false identities.</ p >
925933</ li >
934+ < li > < p class ="first "> < tt class ="docutils literal "> dfhack.units.getIdentity(unit)</ tt > </ p >
935+ < p > Returns the false identity of the unit if it has one, or < em > nil</ em > .</ p >
936+ </ li >
926937< li > < p class ="first "> < tt class ="docutils literal "> dfhack.units.getNemesis(unit)</ tt > </ p >
927938< p > Returns the nemesis record of the unit if it has one, or < em > nil</ em > .</ p >
928939</ li >
@@ -944,6 +955,16 @@ <h3><a class="toc-backref" href="#id16">Units module</a></h3>
944955< li > < p class ="first "> < tt class ="docutils literal "> dfhack.units.setInBurrow(unit,burrow,enable)</ tt > </ p >
945956< p > Adds or removes the unit from the burrow.</ p >
946957</ li >
958+ < li > < p class ="first "> < tt class ="docutils literal "> < span class ="pre "> dfhack.units.getAge(unit[,true_age])</ span > </ tt > </ p >
959+ < p > Returns the age of the unit in years as a floating-point value.
960+ If < tt class ="docutils literal "> true_age</ tt > is true, ignores false identities.</ p >
961+ </ li >
962+ < li > < p class ="first "> < tt class ="docutils literal "> < span class ="pre "> dfhack.units.getProfessionName(unit[,plural])</ span > </ tt > </ p >
963+ < p > Retrieves the profession name using custom profession or raws.</ p >
964+ </ li >
965+ < li > < p class ="first "> < tt class ="docutils literal "> < span class ="pre "> dfhack.units.getCasteProfessionName(race,caste,prof_id[,plural])</ span > </ tt > </ p >
966+ < p > Retrieves the profession name for the given race/caste using raws.</ p >
967+ </ li >
947968</ ul >
948969</ div >
949970< div class ="section " id ="items-module ">
@@ -1061,6 +1082,58 @@ <h3><a class="toc-backref" href="#id20">Event type</a></h3>
10611082</ div >
10621083</ div >
10631084</ div >
1085+ < div class ="section " id ="plugins ">
1086+ < h1 > < a class ="toc-backref " href ="#id21 "> Plugins</ a > </ h1 >
1087+ < p > DFHack plugins may export native functions and events
1088+ to lua contexts. They are automatically imported by
1089+ < tt class ="docutils literal "> < span class ="pre "> mkmodule('plugins.<name>')</ span > </ tt > ; this means that a lua
1090+ module file is still necessary for < tt class ="docutils literal "> require</ tt > to read.</ p >
1091+ < p > The following plugins have lua support.</ p >
1092+ < div class ="section " id ="burrows ">
1093+ < h2 > < a class ="toc-backref " href ="#id22 "> burrows</ a > </ h2 >
1094+ < p > Implements extended burrow manipulations.</ p >
1095+ < p > Events:</ p >
1096+ < ul >
1097+ < li > < p class ="first "> < tt class ="docutils literal "> onBurrowRename.foo = function(burrow)</ tt > </ p >
1098+ < p > Emitted when a burrow might have been renamed either through
1099+ the game UI, or < tt class ="docutils literal "> renameBurrow()</ tt > .</ p >
1100+ </ li >
1101+ < li > < p class ="first "> < tt class ="docutils literal "> onDigComplete.foo = function(job_type,pos,old_tiletype,new_tiletype)</ tt > </ p >
1102+ < p > Emitted when a tile might have been dug out. Only tracked if the
1103+ auto-growing burrows feature is enabled.</ p >
1104+ </ li >
1105+ </ ul >
1106+ < p > Native functions:</ p >
1107+ < ul >
1108+ < li > < p class ="first "> < tt class ="docutils literal "> renameBurrow(burrow,name)</ tt > </ p >
1109+ < p > Renames the burrow, emitting < tt class ="docutils literal "> onBurrowRename</ tt > and updating auto-grow state properly.</ p >
1110+ </ li >
1111+ < li > < p class ="first "> < tt class ="docutils literal "> findByName(burrow,name)</ tt > </ p >
1112+ < p > Finds a burrow by name, using the same rules as the plugin command line interface.
1113+ Namely, trailing < tt class ="docutils literal "> '+'</ tt > characters marking auto-grow burrows are ignored.</ p >
1114+ </ li >
1115+ < li > < p class ="first "> < tt class ="docutils literal "> copyUnits(target,source,enable)</ tt > </ p >
1116+ < p > Applies units from < tt class ="docutils literal "> source</ tt > burrow to < tt class ="docutils literal "> target</ tt > . The < tt class ="docutils literal "> enable</ tt >
1117+ parameter specifies if they are to be added or removed.</ p >
1118+ </ li >
1119+ < li > < p class ="first "> < tt class ="docutils literal "> copyTiles(target,source,enable)</ tt > </ p >
1120+ < p > Applies tiles from < tt class ="docutils literal "> source</ tt > burrow to < tt class ="docutils literal "> target</ tt > . The < tt class ="docutils literal "> enable</ tt >
1121+ parameter specifies if they are to be added or removed.</ p >
1122+ </ li >
1123+ < li > < p class ="first "> < tt class ="docutils literal "> setTilesByKeyword(target,keyword,enable)</ tt > </ p >
1124+ < p > Adds or removes tiles matching a predefined keyword. The keyword
1125+ set is the same as used by the command line.</ p >
1126+ </ li >
1127+ </ ul >
1128+ < p > The lua module file also re-exports or wraps some of the
1129+ functions implemented by the dfhack core for convenience.</ p >
1130+ </ div >
1131+ < div class ="section " id ="sort ">
1132+ < h2 > < a class ="toc-backref " href ="#id23 "> sort</ a > </ h2 >
1133+ < p > Does not export any native functions as of now. Instead, it
1134+ calls lua code to perform the actual ordering of list items.</ p >
1135+ </ div >
1136+ </ div >
10641137</ div >
10651138</ body >
10661139</ html >
0 commit comments