URL:
<http://gna.org/bugs/?15617>
Summary: Scripting: Default script, Ruleset script, and
scenario share namespace
Project: Freeciv
Submitted by: englabenny
Submitted on: söndag 2010-03-14 den 14:07
Category: general
Severity: 3 - Normal
Priority: 1 - Later
Status: None
Assigned to: None
Originator Email:
Open/Closed: Open
Release: 2.2
Discussion Lock: Any
Operating System: None
Planned Release:
_______________________________________________________
Details:
Scripting happens in three places:
default.lua
scripting.lua
script.code in Scenario file
These are all evaluated inside the same lua state, so they share the same
global namespace. This is significant since event callbacks are registered by
name, then looked up in the global namespace by that name.
I suspect the following pattern to be common (default.lua):
signal.connect("hut_enter", "hut_enter_callback")
If the scenario now defines a function called 'hut_enter_callback', that
function will be called instead. However, if the scenario also connects the
same signal to the same-named function, the exact same function will be
called twice.
This namespace sharing is both a curse and a blessing: It allows non-default
rulesets (in script.lua) to override specific functions in the default
ruleset. It allows Scenarios to override specific callbacks from the
ruleset.
I propose that the default ruleset should simply use a consistent naming
scheme, so that accidental overrides are unlikely.
We change hut_enter_callback -> default_hut_enter_callback
And why not all the helper functions the same way, hut_get_mercenaries ->
default_hut_get_mercenaries
I think it would actually be possible to separate these two, we could in fact
have separate lua states for ruleset and scenario, but then we lose the
possible benefits.
_______________________________________________________
Reply to this item at:
<http://gna.org/bugs/?15617>
_______________________________________________
Meddelandet skickades via/av Gna!
http://gna.org/
_______________________________________________
Freeciv-dev mailing list
[email protected]
https://mail.gna.org/listinfo/freeciv-dev