Skip to content

Commit

Permalink
Fixes require not correctly skipping already loaded modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
xanathar committed Oct 3, 2016
1 parent 2b4208b commit 04de254
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 10 deletions.
8 changes: 7 additions & 1 deletion src/DevTools/Playground/Playground.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="samplescript.lua">
<None Include="test.lua">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="test2.lua">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="core.lua">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down
11 changes: 8 additions & 3 deletions src/DevTools/Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ class Program
{
static void Main(string[] args)
{
((ScriptLoaderBase)Script.DefaultOptions.ScriptLoader).ModulePaths = new string[] { "./?", "./?.lua" };

try
{
Script S = new Script();
S.Options.ColonOperatorClrCallbackBehaviour = ColonOperatorBehaviour.TreatAsDotOnUserData;

Table my_table = S.DoString("my_table = { }; return my_table").Table;
my_table["Foo"] = (Action<Table, string>)((self, str) => { Console.WriteLine("!!!" + str); });
S.DoString(@"
require 'test'
require 'test2'
");

S.DoString("my_table:Foo('Ciao');");

}
catch (InterpreterException ex)
Expand Down
5 changes: 5 additions & 0 deletions src/DevTools/Playground/core.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

print "in core.lua"

print(os.date("*t", os.time()).hour)
print(os.date("!*t", os.time()).hour)
6 changes: 0 additions & 6 deletions src/DevTools/Playground/samplescript.lua

This file was deleted.

2 changes: 2 additions & 0 deletions src/DevTools/Playground/test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require "core"
print("in test 1")
2 changes: 2 additions & 0 deletions src/DevTools/Playground/test2.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require "core"
print("in test 2")
4 changes: 4 additions & 0 deletions src/MoonSharp.Interpreter/CoreLib/LoadModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ public static DynValue __require_clr_impl(ScriptExecutionContext executionContex
local res = func(modulename);
if (res == nil) then
res = true;
end
package.loaded[modulename] = res;
return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,9 @@
<Compile Include="..\..\Loaders\InvalidScriptLoader.cs">
<Link>InvalidScriptLoader.cs</Link>
</Compile>
<Compile Include="..\..\Options\ColonOperatorBehaviour.cs">
<Link>ColonOperatorBehaviour.cs</Link>
</Compile>
<Compile Include="..\..\REPL\ReplHistoryNavigator.cs">
<Link>ReplHistoryNavigator.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,9 @@
<Compile Include="..\..\Loaders\InvalidScriptLoader.cs">
<Link>InvalidScriptLoader.cs</Link>
</Compile>
<Compile Include="..\..\Options\ColonOperatorBehaviour.cs">
<Link>ColonOperatorBehaviour.cs</Link>
</Compile>
<Compile Include="..\..\REPL\ReplHistoryNavigator.cs">
<Link>ReplHistoryNavigator.cs</Link>
</Compile>
Expand Down

0 comments on commit 04de254

Please sign in to comment.