Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ If your Lua file causes an error due to mistaken syntax, you can test it at the

`init_function(name, is_first)` and `exit_function` are called at the start and end of processing (once per thread). You can use this to output statistics or even to read a small amount of external data. `is_first` will be true only the first time `init_function` is called.

Tilemaker's functions (`Find`, `Holds`, `Layer`, `Attribute` and the others below) are global variables that are already set when the profile is loaded. So a profile can keep the ones it calls most in locals at its top, which Lua reaches faster than globals: `local Find, Holds, Layer = Find, Holds, Layer`. A function the profile defines with the same name as one of tilemaker's is replaced by tilemaker's.

Other functions are described below and in RELATIONS.md.

### Relations
Expand Down
77 changes: 43 additions & 34 deletions src/osm_lua_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,40 +400,8 @@ lua_State *OsmLuaProcessing::newLuaState(LuaPool &pool) {
return L;
}

OsmLuaProcessing::OsmLuaProcessing(
OSMStore &osmStore,
const class Config &configIn,
class LayerDefinition &layers,
const string &luaFile,
const class ShpMemTiles &shpMemTiles,
class OsmMemTiles &osmMemTiles,
AttributeStore &attributeStore,
class Declutter &declutter,
bool materializeGeometries,
bool isFirst) :
osmStore(osmStore),
luaStateHolder(newLuaState(luaPool)),
luaState(luaStateHolder.L),
shpMemTiles(shpMemTiles),
osmMemTiles(osmMemTiles),
attributeStore(attributeStore),
declutter(declutter),
config(configIn),
currentTags(NULL),
layers(layers),
materializeGeometries(materializeGeometries) {

sigusr1Handler.initialize();
if (vectorLayerMetadataMutexes.size() <= layers.layers.size()) {
vectorLayerMetadataMutexes.resize(layers.layers.size() + 1);
}

// ---- Initialise Lua
g_luaState = &luaState;
luaState.setErrorHandler(lua_error_handler);
luaState.dofile(luaFile.c_str());

osmLuaProcessing = this;
// Register the functions a profile can call as Lua globals.
static void registerLuaFunctions(kaguya::State &luaState) {
luaState["Id"] = &rawId;
luaState["OsmType"] = &rawOsmType;
luaState["AllKeys"] = &rawAllKeys;
Expand Down Expand Up @@ -491,6 +459,47 @@ OsmLuaProcessing::OsmLuaProcessing(
luaState["FindInRelation"] = &rawFindInRelation;
luaState["SetData"] = &rawSetData;
luaState["GetData"] = &rawGetData;
}

OsmLuaProcessing::OsmLuaProcessing(
OSMStore &osmStore,
const class Config &configIn,
class LayerDefinition &layers,
const string &luaFile,
const class ShpMemTiles &shpMemTiles,
class OsmMemTiles &osmMemTiles,
AttributeStore &attributeStore,
class Declutter &declutter,
bool materializeGeometries,
bool isFirst) :
osmStore(osmStore),
luaStateHolder(newLuaState(luaPool)),
luaState(luaStateHolder.L),
shpMemTiles(shpMemTiles),
osmMemTiles(osmMemTiles),
attributeStore(attributeStore),
declutter(declutter),
config(configIn),
currentTags(NULL),
layers(layers),
materializeGeometries(materializeGeometries) {

sigusr1Handler.initialize();
if (vectorLayerMetadataMutexes.size() <= layers.layers.size()) {
vectorLayerMetadataMutexes.resize(layers.layers.size() + 1);
}

// ---- Initialise Lua
g_luaState = &luaState;
luaState.setErrorHandler(lua_error_handler);
osmLuaProcessing = this;
// The built-in functions are registered before the profile is loaded, so that it can keep them in
// locals at the top (local Find, Layer = Find, Layer), and again afterwards, so that they still
// replace profile functions of the same name, as before.
registerLuaFunctions(luaState);
luaState.dofile(luaFile.c_str());
registerLuaFunctions(luaState);

supportsRemappingShapefiles = !!luaState["attribute_function"];
supportsReadingRelations = !!luaState["relation_scan_function"];
supportsPostScanRelations = !!luaState["relation_postscan_function"];
Expand Down
Loading