Skip to content

Commit 2d33f8a

Browse files
committed
fix EvilBeaver#1451: обновление глобального скоупа при загрузке внешнего модуля
1 parent 4131be1 commit 2d33f8a

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/OneScript.Core/Contexts/AttachedContext.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@ namespace OneScript.Contexts
1515
/// </summary>
1616
public sealed class AttachedContext
1717
{
18-
private readonly IVariable[] _variables;
19-
private readonly BslMethodInfo[] _methods;
18+
private IVariable[] _variables;
19+
private BslMethodInfo[] _methods;
2020

2121
public AttachedContext(IAttachableContext source)
2222
{
23-
source.OnAttach(out _variables, out _methods);
2423
Instance = source;
24+
Attach();
25+
}
26+
27+
public void Attach()
28+
{
29+
Instance.OnAttach(out _variables, out _methods);
2530
}
2631

2732
public AttachedContext(IAttachableContext target, IVariable[] vars)

src/ScriptEngine.HostedScript/LibraryLoader.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public void AddModule(string file, string moduleName)
113113
$"en = 'Load module ={moduleName}= in to context from file {file}'")
114114
);
115115
_env.InjectGlobalProperty(null, moduleName, true);
116+
MachineInstance.Current.UpdateGlobals();
116117
}
117118
catch (InvalidOperationException e)
118119
{

src/ScriptEngine/Machine/MachineInstance.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ public void SetMemory(ExecutionContext memory)
6969
_globalContexts = _mem.GlobalNamespace.AttachedContexts.Select(x => new AttachedContext(x))
7070
.ToArray();
7171
}
72+
73+
public void UpdateGlobals()
74+
{
75+
_globalContexts.ForEach(x => x.Attach());
76+
}
7277

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

0 commit comments

Comments
 (0)