Merge pull request #1265 from db48x/allow-calling-blueprint-from-lua

this allows the blueprint plugin to be called from lua
develop
Lethosor 2018-05-11 23:52:16 -04:00 committed by GitHub
commit fbe652d7a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 1 deletions

@ -3349,6 +3349,19 @@ module file is still necessary for ``require`` to read.
The following plugins have lua support. The following plugins have lua support.
blueprint
=========
Native functions:
* ``dig(start, end, name)``
* ``build(start, end, name)``
* ``place(start, end, name)``
* ``query(start, end, name)``
``start`` and ``end`` are tables containing positions (see
``xyz2pos``). ``name`` is used as the basis for the filename.
burrows burrows
======= =======

@ -91,7 +91,7 @@ if (BUILD_SUPPORTED)
DFHACK_PLUGIN(automaterial automaterial.cpp) DFHACK_PLUGIN(automaterial automaterial.cpp)
DFHACK_PLUGIN(automelt automelt.cpp) DFHACK_PLUGIN(automelt automelt.cpp)
DFHACK_PLUGIN(autotrade autotrade.cpp) DFHACK_PLUGIN(autotrade autotrade.cpp)
DFHACK_PLUGIN(blueprint blueprint.cpp) DFHACK_PLUGIN(blueprint blueprint.cpp LINK_LIBRARIES lua)
DFHACK_PLUGIN(burrows burrows.cpp LINK_LIBRARIES lua) DFHACK_PLUGIN(burrows burrows.cpp LINK_LIBRARIES lua)
DFHACK_PLUGIN(building-hacks building-hacks.cpp LINK_LIBRARIES lua) DFHACK_PLUGIN(building-hacks building-hacks.cpp LINK_LIBRARIES lua)
DFHACK_PLUGIN(buildingplan buildingplan.cpp LINK_LIBRARIES buildingplan-lib) DFHACK_PLUGIN(buildingplan buildingplan.cpp LINK_LIBRARIES buildingplan-lib)

@ -6,6 +6,7 @@
#include <Console.h> #include <Console.h>
#include <PluginManager.h> #include <PluginManager.h>
#include "LuaTools.h"
#include "modules/Buildings.h" #include "modules/Buildings.h"
#include "modules/Gui.h" #include "modules/Gui.h"
@ -687,3 +688,44 @@ command_result blueprint(color_ostream &out, vector<string> &parameters)
option |= QUERY; option |= QUERY;
return do_transform(start, end, parameters[3], option); return do_transform(start, end, parameters[3], option);
} }
static int create(lua_State *L, uint32_t options) {
df::coord start, end;
lua_settop(L, 3);
Lua::CheckDFAssign(L, &start, 1);
if (!start.isValid())
luaL_argerror(L, 1, "invalid start position");
Lua::CheckDFAssign(L, &end, 2);
if (!end.isValid())
luaL_argerror(L, 2, "invalid end position");
string filename(lua_tostring(L, 3));
lua_pushboolean(L, do_transform(start, end, filename, options));
return 1;
}
static int dig(lua_State *L) {
return create(L, DIG);
}
static int build(lua_State *L) {
return create(L, BUILD);
}
static int place(lua_State *L) {
return create(L, PLACE);
}
static int query(lua_State *L) {
return create(L, QUERY);
}
DFHACK_PLUGIN_LUA_COMMANDS {
DFHACK_LUA_COMMAND(dig),
DFHACK_LUA_COMMAND(build),
DFHACK_LUA_COMMAND(place),
DFHACK_LUA_COMMAND(query),
DFHACK_LUA_END
};

@ -0,0 +1,14 @@
local _ENV = mkmodule('plugins.blueprint')
--[[
Native functions:
* dig(start, end, name)
* build(start, end, name)
* place(start, end, name)
* query(start, end, name)
--]]
return _ENV