Context Isolation

LynxStar

Chieftain
Joined
Sep 1, 2014
Messages
3
If I have 2 separate contexts is there anyway for me to have Context A, invoke something within Context B's and have it within Context B.

I can get A to call something, that would normally be defined within B, but it executes inside of context A which is worthless to me. I essentially need 2 separate lua scripts that control separate parts of the UI to be able to inform each other of things.

I've tried having the lua script with the update logic listen to the event for the other component of the UI but this doesn't work. My current assumption is a race condition, and I need the other context to execute it's code first. If I could order delegates then this would be acceptable.
 
You'll need to use LuaEvents.

In context B

Code:
LuaEvents.MyEventName.Add(function(msg) print(string.format("Running in UI context B, got '%s' from A", msg)); end)

In context A

Code:
LuaEvents.MyEventName("Boo!");

If you need to get a value from B back into A, A will need to pass a table to B, that B then fills and A then inspects
 
As an alternative to passing a table using LuaEvents, you can use an existing table that is accessible in all Lua states by the global label "MapModData". It's used in World Builder but it's available in-game for anything you need it for.

Either way, it's important to remember that Lua tables don't have a specific association to any particular Lua state, or mod for that matter. It's only the variables that point to them that have specific scope ("global" to a particular state or "local" to a narrower scope). So it's trivial to share Lua data across states or mods. You just need to declare a variable in each state that holds a common single table (by passing it among states), or use the one that already exists.
 
Thanks for the advice, both solutions worked. Lua's making more sense as I dig through it.
 
Back
Top Bottom