diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index 8c76a36f7..4288802ea 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -1337,6 +1337,7 @@ static const LuaWrapper::FunctionReg dfhack_job_module[] = { WRAPM(Job,checkDesignationsNow), WRAPM(Job,isSuitableItem), WRAPM(Job,isSuitableMaterial), + WRAPM(Job,getName), WRAPN(is_equal, jobEqual), WRAPN(is_item_equal, jobItemEqual), { NULL, NULL } diff --git a/library/include/modules/Job.h b/library/include/modules/Job.h index b13d9c5a9..4b3950ebd 100644 --- a/library/include/modules/Job.h +++ b/library/include/modules/Job.h @@ -81,6 +81,7 @@ namespace DFHack DFHACK_EXPORT bool isSuitableItem(df::job_item *item, df::item_type itype, int isubtype); DFHACK_EXPORT bool isSuitableMaterial(df::job_item *item, int mat_type, int mat_index); + DFHACK_EXPORT std::string getName(df::job *job); } DFHACK_EXPORT bool operator== (const df::job_item &a, const df::job_item &b); diff --git a/library/modules/Job.cpp b/library/modules/Job.cpp index a86a82d8a..8750db4c7 100644 --- a/library/modules/Job.cpp +++ b/library/modules/Job.cpp @@ -53,6 +53,7 @@ using namespace std; #include "df/general_ref.h" #include "df/general_ref_unit_workerst.h" #include "df/general_ref_building_holderst.h" +#include "df/interface_button_building_new_jobst.h" using namespace DFHack; using namespace df::enums; @@ -476,3 +477,25 @@ bool Job::isSuitableMaterial(df::job_item *item, int mat_type, int mat_index) return minfo.isValid() && iinfo.matches(*item, &minfo); } + +std::string Job::getName(df::job *job) +{ + CHECK_NULL_POINTER(job); + + std::string desc; + auto button = df::allocate(); + button->reaction_name = job->reaction_name; + button->hist_figure_id = job->hist_figure_id; + button->job_type = job->job_type; + button->item_type = job->item_type; + button->item_subtype = job->item_subtype; + button->mat_type = job->mat_type; + button->mat_index = job->mat_index; + button->item_category = job->item_category; + button->material_category = job->material_category; + + button->getLabel(&desc); + delete button; + + return desc; +}