Skip to content

Commit

Permalink
fix EvilBeaver#1451: обновление глобального скоупа при загрузке внешн…
Browse files Browse the repository at this point in the history
…его модуля
  • Loading branch information
Mr-Rm committed Oct 21, 2024
1 parent 4131be1 commit 2d33f8a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/OneScript.Core/Contexts/AttachedContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ namespace OneScript.Contexts
/// </summary>
public sealed class AttachedContext
{
private readonly IVariable[] _variables;
private readonly BslMethodInfo[] _methods;
private IVariable[] _variables;
private BslMethodInfo[] _methods;

public AttachedContext(IAttachableContext source)
{
source.OnAttach(out _variables, out _methods);
Instance = source;
Attach();
}

public void Attach()
{
Instance.OnAttach(out _variables, out _methods);
}

public AttachedContext(IAttachableContext target, IVariable[] vars)
Expand Down
1 change: 1 addition & 0 deletions src/ScriptEngine.HostedScript/LibraryLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public void AddModule(string file, string moduleName)
$"en = 'Load module ={moduleName}= in to context from file {file}'")
);
_env.InjectGlobalProperty(null, moduleName, true);
MachineInstance.Current.UpdateGlobals();
}
catch (InvalidOperationException e)
{
Expand Down
5 changes: 5 additions & 0 deletions src/ScriptEngine/Machine/MachineInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public void SetMemory(ExecutionContext memory)
_globalContexts = _mem.GlobalNamespace.AttachedContexts.Select(x => new AttachedContext(x))
.ToArray();
}

public void UpdateGlobals()
{
_globalContexts.ForEach(x => x.Attach());
}

public bool IsRunning => _callStack.Count != 0;

Expand Down

0 comments on commit 2d33f8a

Please sign in to comment.