Message
| It turns out that Lua was originally designed precisely as a configuration language. You can easily extend C/C++ with Lua, as Nick said, and then have config files that look like this:
use_ui = false
-- high level search settings
directional_increment = 0.05
probabilistic_roadmap_size = 250
probabilistic_focus_roadmap_points_per_point = 5
probabilistic_focus_roadmap_spread_x = 0.10
probabilistic_focus_roadmap_spread_y = 0.10
use_highlevel_smoothing = false
roadmap_predicate_thresholdz_init = 0.01
roadmap_predicate_thresholdz_inc = 0.01
roadmap_predicate_thresholdz_max = 0.05
roadmap_predicate_maxside_threshold_init = 0.030
roadmap_predicate_maxside_threshold_inc = 0.005
roadmap_predicate_maxside_threshold_max = 0.050
highlevel_goal_proximity = 0.05
highlevel_goal_proximity_factor = 0.3
highlevel_thresholdz_maxjump = 1.5
terrain_polling_num_samples = 50
goal_cost_bias = 0.95
goal_heur_bias = 0.95
highlevel_cost_function = "HighLevelCostFunction"
highlevel_heur_function = "HighLevelHeurFunction"
highlevel_pred_function = "RoadmapVisibilityPredicate"
highlevel_lua_func_file = "highlevel.lua"
-- debugger settings
debug_astar = true
debug_class = true
debug_sim = true
debug_train = true
Or as a more complicated example, like this:
TerrainTypes = {
beach = { name = "beach", tileImage = "tiles/world/beach.png"},
densewoods = { name = "densewoods", tileImage = "tiles/world/dense_woods.png" },
densewoods_snow = { name = "densewoods_snow", tileImage = "tiles/world/dense_woods_snow.png" },
desert = { name = "desert", tileImage = "tiles/world/desert.png" },
farmland = { name = "farmland", tileImage = "tiles/world/farmland.png" },
fields = { name = "fields", tileImage = "tiles/world/fields.png" },
ice = { name = "ice", tileImage = "tiles/world/ice.png" },
jungle = { name = "jungle", tileImage = "tiles/world/jungle.png" },
lightwoods = { name = "lightwoods", tileImage = "tiles/world/light_woods.png" },
lightwoods_snow = { name = "lightwoods_snow", tileImage = "tiles/world/light_woods_snow.png" },
mountain = { name = "mountain", tileImage = "tiles/world/mountain.png" },
ocean = { name = "ocean", tileImage = "tiles/world/ocean.png" },
pass = { name = "pass", tileImage = "tiles/world/pass.png" },
plains = { name = "plains", tileImage = "tiles/world/plains.png" },
range = { name = "range", tileImage = "tiles/world/range.png" },
river = { name = "river", tileImage = "tiles/world/river.png" },
rocky = { name = "rocky", tileImage = "tiles/world/rocky.png" },
savannah = { name = "savannah", tileImage = "tiles/world/savannah.png" },
snow = { name = "snow", tileImage = "tiles/world/snow.png" },
swamp = { name = "swamp", tileImage = "tiles/world/swamp.png" },
tundra = { name = "tundra", tileImage = "tiles/world/tundra.png" },
wasteland = { name = "wasteland", tileImage = "tiles/world/wasteland.png" },
}
The user doesn't have to even know that they're using Lua; I think that the above examples, especially the first one, show that you can have a config file that is Lua but looks very simple. They can even do variables and have if statements in there, if they want to.
Anyhow, you can have the simple syntax as shown above by loading the script and executing it in a special environment. Then, all assignments to "global" variables will be made into that environment table, and you can pick them out of it later.
It's true that you'll have to deal with 0 being 'true' in Lua, but, well, that's life.
You can do similar things in Python, like this:
name = "Building_Wall"
image = "gfx/Buildings/Wall.bmp"
transparency = (255, 0, 255)
# Cap naming convention: cap_<NESW>
#
# Joint naming convention: joint_<direction in which there is no cap>
#
# Base naming convenition: base_<WE>
tiles = {
'cap_0110': (0, 0, 20, 20),
'cap_0111': (40, 0, 20, 20),
'cap_0011': (80, 0, 20, 20),
'cap_1110': (0, 40, 20, 20),
'cap_1111': (40, 40, 20, 20),
'cap_1011': (80, 40, 20, 20),
'cap_1100': (0, 80, 20, 20),
'cap_1101': (40, 80, 20, 20),
'cap_1001': (80, 80, 20, 20),
'cap_1100_baseleft': (240, 0, 20, 20),
'cap_1110_baseleft': (240, 40, 20, 20),
'joint_northeast': (0, 140, 20, 20),
'joint_northwest': (40, 140, 20, 20),
'joint_southeast': (80, 140, 20, 20),
'joint_southwest': (120, 140, 20, 20),
'base_01': (0, 100, 20, 20),
'base_11': (40, 100, 20, 20),
'base_10': (80, 100, 20, 20),
'dummy': (20, 0, 20, 20),
}
but Lua is easier to embed (and much more lightweight) than Python. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | top |
|