-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathChapter8.cs
More file actions
55 lines (47 loc) · 1.13 KB
/
Chapter8.cs
File metadata and controls
55 lines (47 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WattleScript.Interpreter;
using WattleScript.Interpreter.Loaders;
namespace Tutorials.Chapters
{
[Tutorial]
static class Chapter08
{
[Tutorial]
static void EmbeddedResourceScriptLoader()
{
Script script = new Script();
script.Options.ScriptLoader = new EmbeddedResourcesScriptLoader(Assembly.GetExecutingAssembly());
script.DoFile("Scripts/Test.lua");
}
private class MyCustomScriptLoader : ScriptLoaderBase
{
public override object LoadFile(string file, Table globalContext)
{
return string.Format("print ([[A request to load '{0}' has been made]])", file);
}
public override bool ScriptFileExists(string name)
{
return true;
}
}
[Tutorial]
static void CustomScriptLoader()
{
Script script = new Script();
script.Options.ScriptLoader = new MyCustomScriptLoader()
{
ModulePaths = new string[] { "?_module.lua" }
};
script.DoString(@"
require 'somemodule'
f = loadfile 'someothermodule.lua'
f()
");
}
}
}