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: 



Scripting happens in three places:

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

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 ->

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:


  Meddelandet skickades via/av Gna!

Freeciv-dev mailing list

Reply via email to