pioneerspacesim/pioneer — pull request #2560 by robn (2013-11-25 10:20:29+00:00)
Title: Allow Lua to connect an arbitrary method to a property signal

Allows something like:

```Lua
player:Connect("fuel", function ()
print("fuel now "..player.fuel)
end)
```

That is, when the property changes, the function gets called.

As noted in the docs, you do not want to use this for frequently-changing properties (like `fuel`!). For properties that change less often like `cargoUsed` from #2552, its great.

There's one fairly glaring problem with this. It means Lua can be called at any weird time that a property might change in the core code. I figure there's plenty of potential for performance problems and maybe even crashes if you were to do something weird at the wrong time.

I did intend to sort this out by creating a more general core->Lua deferred calling system, where all calls into Lua are queued and executed at a safe place in the frame. This is really hard to do right now because we have some stuff (UI signals, namegen) that call into Lua but need a response on the spot. Getting that right is a huge piece of work that needs serious thought. I don't want to hold this until then because I need it for the station UI. I'm hoping that we can ignore it for now and fix it later.