-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathChapter10.cs
More file actions
36 lines (28 loc) · 875 Bytes
/
Chapter10.cs
File metadata and controls
36 lines (28 loc) · 875 Bytes
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
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;
using WattleScript.Interpreter.Platforms;
namespace Tutorials.Chapters
{
[Tutorial]
static class Chapter10
{
[Tutorial]
static void OverriddenPrint()
{
// redefine print to print in lowercase, for all new scripts
Script.DefaultOptions.DebugPrint = s => Console.WriteLine(s.ToLower());
Script script = new Script();
DynValue fn = script.LoadString("print 'Hello, World!'");
fn.Function.Call(); // this prints "hello, world!"
// redefine print to print in UPPERCASE, for this script only
script.Options.DebugPrint = s => Console.WriteLine(s.ToUpper());
fn.Function.Call(); // this prints "HELLO, WORLD!"
}
}
}