Add Lua reserved name checking and exception hooks
This commit is contained in:
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA.Scripting
|
||||
public void WorldLoaded(World w, WorldRenderer wr)
|
||||
{
|
||||
world = w;
|
||||
AddMapActorGlobals();
|
||||
|
||||
context.Lua["World"] = w;
|
||||
context.Lua["WorldRenderer"] = wr;
|
||||
context.RegisterObject(this, "Internal", false);
|
||||
@@ -55,17 +55,27 @@ namespace OpenRA.Mods.RA.Scripting
|
||||
context.RegisterType(typeof(WRange), "WRange", true);
|
||||
context.RegisterType(typeof(int2), "int2", true);
|
||||
context.RegisterType(typeof(float2), "float2", true);
|
||||
|
||||
var sharedScripts = Game.modData.Manifest.LuaScripts ?? new string[0];
|
||||
if (sharedScripts.Any())
|
||||
context.LoadLuaScripts(f => FileSystem.Open(f).ReadAllText(), sharedScripts);
|
||||
|
||||
AddMapActorGlobals();
|
||||
|
||||
context.LoadLuaScripts(f => w.Map.Container.GetContent(f).ReadAllText(), info.LuaScripts);
|
||||
|
||||
context.InvokeLuaFunction("WorldLoaded");
|
||||
}
|
||||
|
||||
void AddMapActorGlobals()
|
||||
{
|
||||
foreach (var kv in world.WorldActor.Trait<SpawnMapActors>().Actors)
|
||||
context.Lua[kv.Key] = kv.Value;
|
||||
{
|
||||
if (context.Lua[kv.Key] != null)
|
||||
context.ShowErrorMessage("{0}: The global name '{1}' is reserved and may not be used by map actor {2}".F(GetType().Name, kv.Key, kv.Value), null);
|
||||
else
|
||||
context.Lua[kv.Key] = kv.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
|
||||
Reference in New Issue
Block a user