Xanathar 11 лет назад
Родитель
Сommit
8215b1afaf
46 измененных файлов с 1355 добавлено и 106 удалено
  1. 1 1
      src/MoonSharp.Debugger/MainForm.cs
  2. 1 1
      src/MoonSharp.Debugger/ValueBrowser.Designer.cs
  3. 2 2
      src/MoonSharp.Documentation/Content/Welcome.aml
  4. 1 1
      src/MoonSharp.Documentation/ContentLayout.content
  5. 5 5
      src/MoonSharp.Interpreter.Tests/TestMore/203-lexico.t
  6. 4 4
      src/MoonSharp.Interpreter.Tests/TestMore/301-basic.t
  7. 1 1
      src/MoonSharp.Interpreter.Tests/TestMore/306-math.t
  8. 2 3
      src/MoonSharp.Interpreter.Tests/TestMore/TestMoreTests.cs
  9. 1 1
      src/MoonSharp.Interpreter/CoreLib/Bit32Module.cs
  10. 4 0
      src/MoonSharp.Interpreter/CoreLib/ErrorHandling.cs
  11. 56 0
      src/MoonSharp.Interpreter/CoreLib/IO/BinaryEncoding.cs
  12. 137 0
      src/MoonSharp.Interpreter/CoreLib/IO/FileUserData.cs
  13. 162 0
      src/MoonSharp.Interpreter/CoreLib/IO/FileUserDataBase.cs
  14. 220 0
      src/MoonSharp.Interpreter/CoreLib/IoMethods.cs
  15. 45 2
      src/MoonSharp.Interpreter/CoreLib/LoadMethods.cs
  16. 1 1
      src/MoonSharp.Interpreter/CoreLib/MathModule.cs
  17. 0 39
      src/MoonSharp.Interpreter/CoreLib/OsMethods.cs
  18. 125 0
      src/MoonSharp.Interpreter/CoreLib/OsSystemMethods.cs
  19. 266 0
      src/MoonSharp.Interpreter/CoreLib/OsTimeMethods.cs
  20. 25 0
      src/MoonSharp.Interpreter/DataTypes/CallbackArguments.cs
  21. 1 1
      src/MoonSharp.Interpreter/DataTypes/DataType.cs
  22. 28 5
      src/MoonSharp.Interpreter/DataTypes/DynValue.cs
  23. 1 1
      src/MoonSharp.Interpreter/DataTypes/InteropAccessMode.cs
  24. 1 1
      src/MoonSharp.Interpreter/DataTypes/Table.cs
  25. 4 0
      src/MoonSharp.Interpreter/DataTypes/TypeValidationFlags.cs
  26. 1 1
      src/MoonSharp.Interpreter/DataTypes/WellKnownSymbols.cs
  27. 12 1
      src/MoonSharp.Interpreter/Errors/ScriptRuntimeException.cs
  28. 15 0
      src/MoonSharp.Interpreter/Execution/ScriptExecutionContext.cs
  29. 1 1
      src/MoonSharp.Interpreter/Execution/VM/OpCode.cs
  30. 1 1
      src/MoonSharp.Interpreter/Execution/VM/Processor/Processor_InstructionLoop.cs
  31. 5 1
      src/MoonSharp.Interpreter/Interop/UserDataMethodDescriptor.cs
  32. 3 2
      src/MoonSharp.Interpreter/Loaders/ClassicLuaScriptLoader.cs
  33. 6 7
      src/MoonSharp.Interpreter/Modules/CoreModules.cs
  34. 17 2
      src/MoonSharp.Interpreter/Modules/ModuleRegister.cs
  35. 14 1
      src/MoonSharp.Interpreter/MoonSharp.Interpreter.csproj
  36. 64 0
      src/MoonSharp.Interpreter/RuntimeAbstraction/Platform.cs
  37. 20 0
      src/MoonSharp.Interpreter/RuntimeAbstraction/PlatformImplementations/Clr2Platform.cs
  38. 15 0
      src/MoonSharp.Interpreter/RuntimeAbstraction/PlatformImplementations/Clr4Platform.cs
  39. 15 0
      src/MoonSharp.Interpreter/RuntimeAbstraction/PlatformImplementations/MonoPlatform.cs
  40. 15 0
      src/MoonSharp.Interpreter/RuntimeAbstraction/PlatformImplementations/UnityPlatform.cs
  41. 21 0
      src/MoonSharp.Interpreter/RuntimeAbstraction/PlatformImplementations/UnityWebPlatform.cs
  42. 32 13
      src/MoonSharp.Interpreter/Script.cs
  43. 1 1
      src/MoonSharp/Program.cs
  44. 1 1
      src/MoonSharpTests/Program.cs
  45. 2 2
      src/PerformanceComparison/Program.cs
  46. 0 3
      src/moonsharp.sln

+ 1 - 1
src/MoonSharp.Debugger/MainForm.cs

@@ -88,7 +88,7 @@ namespace MoonSharp.Debugger
 			m_Script.AttachDebugger(this);
 
 			Thread m_Debugger = new Thread(DebugMain);
-			m_Debugger.Name = "Moon# Execution Thread";
+			m_Debugger.Name = "MoonSharp Execution Thread";
 			m_Debugger.IsBackground = true;
 			m_Debugger.Start();
 		}

+ 1 - 1
src/MoonSharp.Debugger/ValueBrowser.Designer.cs

@@ -286,7 +286,7 @@
 			this.MaximizeBox = false;
 			this.MinimizeBox = false;
 			this.Name = "ValueBrowser";
-			this.Text = "Moon# Value Browser";
+			this.Text = "MoonSharp Value Browser";
 			this.Load += new System.EventHandler(this.ValueBrowser_Load);
 			this.toolStrip1.ResumeLayout(false);
 			this.toolStrip1.PerformLayout();

+ 2 - 2
src/MoonSharp.Documentation/Content/Welcome.aml

@@ -4,8 +4,8 @@
 		<introduction>
       <para>This is the API reference for the MoonSharp.Interpreter assembly.</para>
       <para>To get started, please visit <externalLink>
-        <linkText>the Moon# homepage</linkText>
-        <linkAlternateText>Moon# homepage</linkAlternateText>
+        <linkText>the MoonSharp homepage</linkText>
+        <linkAlternateText>MoonSharp homepage</linkAlternateText>
         <linkUri>http://www.moonsharp.org</linkUri>
       </externalLink>.</para>
     </introduction>

+ 1 - 1
src/MoonSharp.Documentation/ContentLayout.content

@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Topics>
-  <Topic id="06af6655-1018-45a9-9efb-b6a42cb4a88a" visible="True" isDefault="true" isSelected="true" title="Moon#" tocTitle="Moon#" linkText="http://www.moonsharp.org" />
+  <Topic id="06af6655-1018-45a9-9efb-b6a42cb4a88a" visible="True" isDefault="true" isSelected="true" title="MoonSharp" tocTitle="MoonSharp" linkText="http://www.moonsharp.org" />
 </Topics>

+ 5 - 5
src/MoonSharp.Interpreter.Tests/TestMore/203-lexico.t

@@ -55,7 +55,7 @@ like(msg, "^[^:]+:%d+: .- near")
 f, msg = load [[a = "A\Z"]]
 like(msg, "^[^:]+:%d+: .- escape .- near")
 
--- Moon# - changed tests because of different parser bail out errors
+-- MoonSharp - changed tests because of different parser bail out errors
 
 f, msg = load [[a = " unfinished string ]]
 like(msg, ".+")
@@ -77,7 +77,7 @@ like(msg, ".+")
 f, msg = load "a = [== invalid long string delimiter "
 like(msg, ".+")
 
--- End of Moon# changes
+-- End of MoonSharp changes
 
 a = 'alo\n123"'
 is('alo\n123"', a)
@@ -93,7 +93,7 @@ is("alo\n\z
 
 f, msg = load [[a = " escape \z unauthorized
 new line" ]]
-like(msg, "^[^:]+:%d+: .+") -- Moon# changed error msg
+like(msg, "^[^:]+:%d+: .+") -- MoonSharp changed error msg
 
 is(3.0, 3)
 is(314.16e-2, 3.1416)
@@ -101,7 +101,7 @@ is(0.31416E1, 3.1416)
 is(0xff, 255)
 is(0x56, 86)
 --[[
-Moon# : no intention to support hex floats
+MoonSharp : no intention to support hex floats
 
  is(0x0.1E, 0x1E / 0x100, "hexf1")        -- 0.1171875
 is(0xA23p-4, 0xA23 / (2^4), "hexf2")     -- 162.1875
@@ -109,7 +109,7 @@ is(0X1.921FB54442D18P+1, (1 + 0x921FB54442D18/0x10000000000000) * 2, "hexf3")
 --]]
 
 f, msg = load [[a = 12e34e56]]
-like(msg, ".+") -- Moon# changed error msg
+like(msg, ".+") -- MoonSharp changed error msg
 
 --[===[
 --[[

+ 4 - 4
src/MoonSharp.Interpreter.Tests/TestMore/301-basic.t

@@ -27,7 +27,7 @@ L<http://www.lua.org/manual/5.2/manual.html#6.1>.
 
 --]]
 
--- Moon# note : THIS SUITE WAS HEAVILY CUT FOR NOT APPLIABLE TESTS
+-- MoonSharp note : THIS SUITE WAS HEAVILY CUT FOR NOT APPLIABLE TESTS
 
 
 require 'Test.More'
@@ -259,7 +259,7 @@ is(rawset(t, 'a', 'letter a'), t, "function rawset")
 is(t.a, 'letter a')
 
 error_like(function () t = {}; rawset(t, nil, 42) end,
-           "^[^:]+:%d+: table index is nil",   -- changed this for moon#, but we stay as it is!
+           "^[^:]+:%d+: table index is nil",   -- changed this for MoonSharp, but we stay as it is!
            "function rawset (table index is nil)")
 
 is(select('#'), 0, "function select")
@@ -285,7 +285,7 @@ is(type(print), 'function')
 is(type(type), 'function')
 is(type(true), 'boolean')
 is(type(nil), 'nil')
--- is(type(io.stdin), 'userdata') -- no stdin in moon# so far 
+-- is(type(io.stdin), 'userdata') -- no stdin in MoonSharp so far 
 is(type(type(X)), 'string')
 
 a = nil
@@ -333,7 +333,7 @@ error_like(function () tostring() end,
            "^[^:]+:%d+: bad argument #1 to 'tostring' %(value expected%)",
            "function tostring (no arg)")
 
---[[ Moon# : this is intentional - we support pack and unpack outside the table namespace (or whatever they are) 
+--[[ MoonSharp : this is intentional - we support pack and unpack outside the table namespace (or whatever they are) 
 if (platform and platform.compat) or jit then
     type_ok(unpack, 'function', "function unpack")
 else

+ 1 - 1
src/MoonSharp.Interpreter.Tests/TestMore/306-math.t

@@ -108,7 +108,7 @@ like(math.random(9), '^%d$', "function random 1 arg")
 like(math.random(10, 19), '^1%d$', "function random 2 arg")
 
 --[[
-Moon# : math.random normalizes inputs, and we are happy with that
+MoonSharp : math.random normalizes inputs, and we are happy with that
 
 if jit then
     todo("LuaJIT intentional. Don't check empty interval.", 2)

+ 2 - 3
src/MoonSharp.Interpreter.Tests/TestMore/TestMoreTests.cs

@@ -256,10 +256,9 @@ namespace MoonSharp.Interpreter.Tests
 
 
 		[Test]
-		[Ignore]
-		public void TestMore_307_os()
+		public void TestMore_309_os()
 		{
-			TapRunner.Run(@"TestMore\307-os.t");
+			TapRunner.Run(@"TestMore\309-os.t");
 		}
 
 

+ 1 - 1
src/MoonSharp.Interpreter/CoreLib/Bit32Module.cs

@@ -7,7 +7,7 @@ using MoonSharp.Interpreter.Execution;
 namespace MoonSharp.Interpreter.CoreLib
 {
 	[MoonSharpModule(Namespace="bit32")]
-	public class MathModule
+	public class Bit32Module
 	{
 		static readonly uint[] BITS = new uint[] { 
 							0x1, 0x2, 0x4, 0x8,

+ 4 - 0
src/MoonSharp.Interpreter/CoreLib/ErrorHandling.cs

@@ -51,6 +51,10 @@ namespace MoonSharp.Interpreter.CoreLib
 					return DynValue.NewTupleNested(DynValue.False, DynValue.NewString(ex.Message));
 				}
 			}
+			else if (args[0].Type != DataType.Function)
+			{
+				return DynValue.NewTupleNested(DynValue.False, DynValue.NewString("attempt to pcall a non-function"));
+			}
 			else
 			{
 				return DynValue.NewTailCallReq(new TailCallData()

+ 56 - 0
src/MoonSharp.Interpreter/CoreLib/IO/BinaryEncoding.cs

@@ -0,0 +1,56 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace MoonSharp.Interpreter.CoreLib.IO
+{
+	class BinaryEncoding : Encoding
+	{
+		public BinaryEncoding()
+			: base()
+		{
+
+		}
+
+		public override int GetByteCount(char[] chars, int index, int count)
+		{
+			return count;
+		}
+
+		public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
+		{
+			for (int i = 0; i < charCount; i++)
+			{
+				bytes[byteIndex + i] = (byte)((int)chars[charIndex + i]);
+			}
+
+			return charCount;
+		}
+
+		public override int GetCharCount(byte[] bytes, int index, int count)
+		{
+			return count;
+		}
+
+		public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
+		{
+			for (int i = 0; i < byteCount; i++)
+			{
+				chars[charIndex + i] = (char)((int)bytes[byteIndex + i]);
+			}
+
+			return byteCount;
+		}
+
+		public override int GetMaxByteCount(int charCount)
+		{
+			return charCount;
+		}
+
+		public override int GetMaxCharCount(int byteCount)
+		{
+			return byteCount;
+		}
+	}
+}

+ 137 - 0
src/MoonSharp.Interpreter/CoreLib/IO/FileUserData.cs

@@ -0,0 +1,137 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+
+namespace MoonSharp.Interpreter.CoreLib.IO
+{
+	class FileUserData : FileUserDataBase
+	{
+		Stream m_Stream;
+		StreamReader m_Reader;
+		StreamWriter m_Writer;
+		bool m_Closed = false;
+
+		public FileUserData(string filename, Encoding encoding, string mode)
+		{
+			m_Stream = new FileStream(filename, ParseFileMode(mode));
+
+			if (m_Stream.CanRead)
+				m_Reader = new StreamReader(m_Stream, encoding);
+
+			if (m_Stream.CanWrite)
+				m_Writer = new StreamWriter(m_Stream, encoding);
+		}
+
+		private FileMode ParseFileMode(string mode)
+		{
+			mode = mode.Replace("b", "");
+
+			if (mode == "r")
+				return FileMode.Open;
+			else if (mode == "r+")
+				return FileMode.OpenOrCreate;
+			else if (mode == "w")
+				return FileMode.Create;
+			else if (mode == "w+")
+				return FileMode.Truncate;
+			else
+				return FileMode.Append;
+		}
+
+		protected override bool Eof()
+		{
+			if (m_Reader != null)
+				return m_Reader.EndOfStream;
+			else
+				return false;
+		}
+
+		protected override string ReadLine()
+		{
+			return m_Reader.ReadLine();
+		}
+
+		protected override string ReadToEnd()
+		{
+			return m_Reader.ReadToEnd();
+		}
+
+		protected override string ReadBuffer(int p)
+		{
+			char[] buffer = new char[p];
+			int length = m_Reader.ReadBlock(buffer, 0, p);
+			return new string(buffer, 0, length);
+		}
+
+		protected override char Peek()
+		{
+			return (char)m_Reader.Peek();
+		}
+
+		protected override void Write(string value)
+		{
+			m_Writer.Write(value);
+		}
+
+		public override void close()
+		{
+			if (m_Reader != null)
+				m_Reader.Dispose();
+
+			if (m_Writer != null)
+				m_Writer.Dispose();
+
+			m_Stream.Dispose();
+
+			m_Closed = true;
+		}
+
+		public override void flush()
+		{
+			if (m_Writer != null)
+				m_Writer.Flush();
+		}
+
+		public override void lines()
+		{
+			throw new NotImplementedException();
+		}
+
+		public override long seek(string whence, long offset)
+		{
+			if (whence != null)
+			{
+				if (whence == "set")
+				{
+					m_Stream.Seek(offset, SeekOrigin.Begin);
+				}
+				else if (whence == "cur")
+				{
+					m_Stream.Seek(offset, SeekOrigin.Current);
+				}
+				else if (whence == "end")
+				{
+					m_Stream.Seek(offset, SeekOrigin.End);
+				}
+				else
+				{
+					return -1;
+				}
+			}
+
+			return m_Stream.Position;
+		}
+
+		public override void setvbuf(string mode, int size)
+		{
+			m_Writer.AutoFlush = (mode == "no" || mode == "line");
+		}
+
+		protected internal override bool isopen()
+		{
+			return !m_Closed;
+		}
+	}
+}

+ 162 - 0
src/MoonSharp.Interpreter/CoreLib/IO/FileUserDataBase.cs

@@ -0,0 +1,162 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using MoonSharp.Interpreter.Execution;
+
+namespace MoonSharp.Interpreter.CoreLib.IO
+{
+	public abstract class FileUserDataBase
+	{
+		public DynValue read(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			if (args.Count == 0)
+			{
+				string str = ReadLine();
+				str = str.TrimEnd('\n', '\r');
+				return DynValue.NewString(str);
+			}
+			else
+			{
+				List<DynValue> rets = new List<DynValue>();
+
+				for (int i = 0; i < args.Count; i++)
+				{
+					DynValue v;
+
+					if (args[i].Type == DataType.Number)
+					{
+						string str = ReadBuffer((int)args[i].Number);
+						v = DynValue.NewString(str);
+					}
+					else 
+					{
+						string opt = args.AsType(i, "read", DataType.String, false).String;
+
+						if (Eof())
+						{
+							v = opt.StartsWith("*a") ? DynValue.NewString("") : DynValue.Nil;
+						}
+						else if (opt.StartsWith("*n"))
+						{
+							double? d = ReadNumber();
+
+							if (d.HasValue)
+								v = DynValue.NewNumber(d.Value);
+							else
+								v = DynValue.Nil;
+						}
+						else if (opt.StartsWith("*a"))
+						{
+							string str = ReadToEnd();
+							v = DynValue.NewString(str);
+						}
+						else if (opt.StartsWith("*l"))
+						{
+							string str = ReadLine();
+							str = str.TrimEnd('\n', '\r');
+							v = DynValue.NewString(str);
+						}
+						else if (opt.StartsWith("*L"))
+						{
+							string str = ReadLine();
+							str = str.TrimEnd('\n', '\r');
+							v = DynValue.NewString(str);
+						}
+						else
+						{
+							throw ScriptRuntimeException.BadArgument(i, "read", "invalid option");
+						}
+					}
+
+					rets.Add(v);
+				}
+
+				return DynValue.NewTuple(rets.ToArray());
+			}
+		}
+
+
+		public DynValue write(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			try
+			{
+				for (int i = 0; i < args.Count; i++)
+				{
+					//string str = args.AsStringUsingMeta(executionContext, i, "file:write");
+					string str = args.AsType(i, "write", DataType.String, false).String;
+					Write(str);
+				}
+
+				return UserData.Create(this);
+			}
+			catch (Exception ex)
+			{
+				return DynValue.NewTuple(DynValue.Nil, DynValue.NewString(ex.Message));
+			}
+		}
+
+		double? ReadNumber()
+		{
+			string chr = "";
+
+			while (!Eof())
+			{
+				char c = Peek();
+				if (char.IsWhiteSpace(c))
+				{
+					ReadBuffer(1);
+				}
+				else if (IsNumericChar(c, chr))
+				{
+					ReadBuffer(1);
+					chr += c;
+				}
+				else break;
+			}
+
+			double d;
+
+			if (double.TryParse(chr, out d))
+			{
+				return d;
+			}
+			else
+			{
+				return null;
+			}
+		}
+
+		private bool IsNumericChar(char c, string numAsFar)
+		{
+			if (char.IsDigit(c))
+				return true;
+
+			if (c == '-')
+				return numAsFar.Length == 0;
+
+			if (c == '.')
+				return !numAsFar.Contains('.');
+
+			if (c == 'E' || c == 'e')
+				return !(numAsFar.Contains('E') || numAsFar.Contains('e'));
+
+			return false;
+		}
+
+		protected abstract bool Eof();
+		protected abstract string ReadLine();
+		protected abstract string ReadBuffer(int p);
+		protected abstract string ReadToEnd();
+		protected abstract char Peek();
+		protected abstract void Write(string value);
+
+
+		protected internal abstract bool isopen();
+		public abstract void close();
+		public abstract void flush();
+		public abstract void lines();
+		public abstract long seek(string whence, long offset);
+		public abstract void setvbuf(string mode, int size);
+	}
+}

+ 220 - 0
src/MoonSharp.Interpreter/CoreLib/IoMethods.cs

@@ -0,0 +1,220 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using MoonSharp.Interpreter.CoreLib.IO;
+using MoonSharp.Interpreter.Execution;
+
+namespace MoonSharp.Interpreter.CoreLib
+{
+	[MoonSharpModule(Namespace = "io")]
+	public class IoMethods
+	{
+		enum DefaultFiles
+		{
+			In,
+			Out,
+			Err
+		}
+
+		public static void MoonSharpInit(Table globalTable, Table stringTable)
+		{
+			UserData.RegisterType<FileUserDataBase>();
+		}
+
+		static FileUserDataBase stdin;
+
+		static FileUserDataBase stdout;
+
+		static FileUserDataBase stderr;
+
+		static FileUserDataBase GetDefaultFile(ScriptExecutionContext executionContext, DefaultFiles file)
+		{
+			Table R = executionContext.GetScript().Registry;
+
+			DynValue ff = R.Get("853BEAAF298648839E2C99D005E1DF94_" + file.ToString());
+
+			if (ff.IsNil())
+			{
+				switch (file)
+				{
+					case DefaultFiles.In:
+						return stdin;
+					case DefaultFiles.Out:
+						return stdout;
+					case DefaultFiles.Err:
+						return stderr;
+					default:
+						throw new InternalErrorException("DefaultFiles value defaulted");
+				}
+			}
+			else
+			{
+				return ff.CheckUserDataType<FileUserDataBase>("getdefaultfile(" + file.ToString() + ")");
+			}
+		}
+
+		static void SetDefaultFile(ScriptExecutionContext executionContext, DefaultFiles file, FileUserDataBase fileHandle)
+		{
+			Table R = executionContext.GetScript().Registry;
+			R.Set("853BEAAF298648839E2C99D005E1DF94_" + file.ToString(), UserData.Create(fileHandle));
+		}
+		
+
+
+		[MoonSharpMethod]
+		public static DynValue close(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			FileUserDataBase outp = args.AsUserData<FileUserDataBase>(0, "close", true) ?? GetDefaultFile(executionContext, DefaultFiles.Out);
+			outp.close();
+			return DynValue.Void;
+		}
+
+		[MoonSharpMethod]
+		public static DynValue flush(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			FileUserDataBase outp = args.AsUserData<FileUserDataBase>(0, "close", true) ?? GetDefaultFile(executionContext, DefaultFiles.Out);
+			outp.flush();
+			return DynValue.Void;
+		}
+
+
+		[MoonSharpMethod]
+		public static DynValue input(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			return HandleDefaultStreamSetter(executionContext, args, DefaultFiles.In);
+		}
+
+		[MoonSharpMethod]
+		public static DynValue output(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			return HandleDefaultStreamSetter(executionContext, args, DefaultFiles.Out);
+		}
+
+		private static DynValue HandleDefaultStreamSetter(ScriptExecutionContext executionContext, CallbackArguments args, DefaultFiles defaultFiles)
+		{
+			if (args.Count == 0)
+			{
+				var file = GetDefaultFile(executionContext, defaultFiles);
+				return UserData.Create(file);
+			}
+
+			FileUserDataBase inp = null;
+
+			if (args[0].Type == DataType.String || args[0].Type == DataType.Number)
+			{
+				string fileName = args[0].CastToString();
+				inp = Open(fileName, Encoding.UTF8, "w");
+			}
+			else
+			{
+				inp = args.AsUserData<FileUserDataBase>(0, "input", false);
+			}
+
+			SetDefaultFile(executionContext, defaultFiles, inp);
+
+			return UserData.Create(inp);
+		}
+
+		[MoonSharpMethod]
+		public static DynValue lines(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			string filename = args.AsType(0, "lines", DataType.String, false).String;
+
+			try
+			{
+				string[] readLines = System.IO.File.ReadAllLines(filename);
+
+				IEnumerable<DynValue> retLines = readLines
+					.Select(s => DynValue.NewString(s))
+					.Concat(new DynValue[] { DynValue.Nil });
+
+				return DynValue.FromObject(executionContext.GetScript(), retLines);
+			}
+			catch(Exception ex)
+			{
+				throw new ScriptRuntimeException(ex);
+			}
+		}
+
+		[MoonSharpMethod]
+		public static DynValue open(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			string filename = args.AsType(0, "open", DataType.String, false).String;
+			DynValue vmode = args.AsType(1, "open", DataType.String, true);
+			DynValue vencoding = args.AsType(2, "open", DataType.String, true);
+
+			string mode = vmode.IsNil() ? "r" : vmode.String;
+			string encoding = vencoding.IsNil() ? null : vencoding.String;
+
+			// list of codes: http://msdn.microsoft.com/en-us/library/vstudio/system.text.encoding%28v=vs.90%29.aspx.
+			// In addition, "binary" is available.
+			Encoding e = null;
+			bool isBinary = mode.Contains('b');
+
+			if (encoding == "binary")
+			{
+				isBinary = true;
+			}
+			else if (encoding == null)
+			{
+				if (!isBinary) e = Encoding.UTF8;
+			}
+			else
+			{
+				if (isBinary)
+					throw new ScriptRuntimeException("Can't specify encodings other than nil or 'binary' for binary streams.");
+
+				e = Encoding.GetEncoding(encoding);
+			}
+
+			return UserData.Create(Open(filename, e, mode));
+		}
+
+		[MoonSharpMethod]
+		public static DynValue type(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			if (args[0].Type != DataType.UserData)
+				return DynValue.Nil;
+
+			FileUserDataBase file = args[0].UserData.Object as FileUserDataBase;
+
+			if (file == null)
+				return DynValue.Nil;
+			else if (file.isopen())
+				return DynValue.NewString("file");
+			else
+				return DynValue.NewString("closed file");
+		}
+
+		[MoonSharpMethod]
+		public static DynValue read(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			FileUserDataBase file = GetDefaultFile(executionContext, DefaultFiles.In);
+			return file.read(executionContext, args);
+		}
+
+		[MoonSharpMethod]
+		public static DynValue write(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			FileUserDataBase file = GetDefaultFile(executionContext, DefaultFiles.Out);
+			return file.write(executionContext, args);
+		}
+
+		[MoonSharpMethod]
+		public static DynValue tmpfile(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			FileUserDataBase file = Open(System.IO.Path.GetTempFileName(), Encoding.UTF8, "w");
+			return UserData.Create(file);
+		}
+
+		private static FileUserDataBase Open(string filename, Encoding encoding, string mode)
+		{
+			return new FileUserData(filename, encoding, mode);
+		}
+
+
+
+	}
+
+}

+ 45 - 2
src/MoonSharp.Interpreter/CoreLib/LoadMethods.cs

@@ -25,6 +25,21 @@ namespace MoonSharp.Interpreter.CoreLib
 		// The string mode is ignored, and assumed to be "t"; 
 		[MoonSharpMethod]
 		public static DynValue load(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			return load_impl(executionContext, args, null);
+		}
+
+		// loadsafe (ld [, source [, mode [, env]]])
+		// ----------------------------------------------------------------
+		// Same as load, except that "env" defaults to the current environment of the function
+		// calling load, instead of the actual global environment.
+		[MoonSharpMethod]
+		public static DynValue loadsafe(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			return load_impl(executionContext, args, GetSafeDefaultEnv(executionContext));
+		}
+
+		public static DynValue load_impl(ScriptExecutionContext executionContext, CallbackArguments args, Table defaultEnv)
 		{
 			try
 			{
@@ -58,7 +73,7 @@ namespace MoonSharp.Interpreter.CoreLib
 				DynValue env = args.AsType(3, "load", DataType.Table, true);
 
 				DynValue fn = S.LoadString(script,
-					!env.IsNil() ? env.Table : null,
+					!env.IsNil() ? env.Table : defaultEnv,
 					!source.IsNil() ? source.String : "=(load)");
 
 				return fn;
@@ -75,6 +90,23 @@ namespace MoonSharp.Interpreter.CoreLib
 		// if no file name is given. INCOMPAT: stdin not supported, mode ignored
 		[MoonSharpMethod]
 		public static DynValue loadfile(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			return loadfile_impl(executionContext, args, null);
+		}
+
+		// loadfile ([filename [, mode [, env]]])
+		// ----------------------------------------------------------------
+		// Same as loadfile, except that "env" defaults to the current environment of the function
+		// calling load, instead of the actual global environment.
+		[MoonSharpMethod]
+		public static DynValue loadfilesafe(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			return loadfile_impl(executionContext, args, GetSafeDefaultEnv(executionContext));
+		}
+
+
+
+		private static DynValue loadfile_impl(ScriptExecutionContext executionContext, CallbackArguments args, Table defaultEnv)
 		{
 			try
 			{
@@ -82,7 +114,7 @@ namespace MoonSharp.Interpreter.CoreLib
 				DynValue filename = args.AsType(0, "loadfile", DataType.String, false);
 				DynValue env = args.AsType(2, "loadfile", DataType.Table, true);
 
-				DynValue fn = S.LoadFile(filename.String, env.IsNil() ? null : env.Table);
+				DynValue fn = S.LoadFile(filename.String, env.IsNil() ? defaultEnv : env.Table);
 
 				return fn;
 			}
@@ -92,6 +124,17 @@ namespace MoonSharp.Interpreter.CoreLib
 			}
 		}
 
+
+		private static Table GetSafeDefaultEnv(ScriptExecutionContext executionContext)
+		{
+			Table env = executionContext.CurrentGlobalEnv;
+
+			if (env == null)
+				throw new ScriptRuntimeException("current environment cannot be backtracked.");
+
+			return env;
+		}
+
 		//dofile ([filename])
 		//--------------------------------------------------------------------------------------------------------------
 		//Opens the named file and executes its contents as a Lua chunk. When called without arguments, 

+ 1 - 1
src/MoonSharp.Interpreter/CoreLib/MathModule.cs

@@ -7,7 +7,7 @@ using MoonSharp.Interpreter.Execution;
 namespace MoonSharp.Interpreter.CoreLib
 {
 	[MoonSharpModule(Namespace="math")]
-	public class Bit32Module
+	public class MathModule
 	{
 		[MoonSharpConstant]
 		public const double pi = Math.PI;

+ 0 - 39
src/MoonSharp.Interpreter/CoreLib/OsMethods.cs

@@ -1,39 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using MoonSharp.Interpreter.Execution;
-
-namespace MoonSharp.Interpreter.CoreLib
-{
-		[MoonSharpModule(Namespace = "os")]
-	public  class OsMethods
-	{
-		static DateTime Time0 = DateTime.UtcNow;
-		static DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
-
-		[MoonSharpMethod]
-		public static DynValue clock(ScriptExecutionContext executionContext, CallbackArguments args)
-		{
-			return DynValue.NewNumber((DateTime.UtcNow - Time0).TotalSeconds);
-		}
-
-		[MoonSharpMethod]
-		public static DynValue time(ScriptExecutionContext executionContext, CallbackArguments args)
-		{
-			DateTime date = DateTime.UtcNow;
-
-			if (args.Count > 0)
-			{
-
-
-			}
-
-
-			return DynValue.NewNumber(Math.Floor(( date - Epoch).TotalSeconds));
-
-
-		}
-		
-	}
-}

+ 125 - 0
src/MoonSharp.Interpreter/CoreLib/OsSystemMethods.cs

@@ -0,0 +1,125 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Text;
+using MoonSharp.Interpreter.Execution;
+
+namespace MoonSharp.Interpreter.CoreLib
+{
+	[MoonSharpModule(Namespace = "os")]
+	public class OsSystemMethods
+	{
+		[MoonSharpMethod]
+		public static DynValue execute(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			DynValue v = args.AsType(0, "execute", DataType.String, true);
+
+			if (v.IsNil())
+			{
+				return DynValue.NewBoolean(true);
+			}
+			else
+			{
+				try
+				{
+					ProcessStartInfo psi = new ProcessStartInfo("cmd.exe", string.Format("/C {0}", v.String));
+					psi.ErrorDialog = false;
+
+					Process proc = Process.Start(psi);
+					proc.WaitForExit();
+					return DynValue.NewTuple(
+						DynValue.True,
+						DynValue.NewString("exit"),
+						DynValue.NewNumber(proc.ExitCode));
+				}
+				catch (Exception)
+				{
+					// +++ bad to swallow.. 
+					return DynValue.Nil;
+				}
+			}
+		}
+
+		[MoonSharpMethod]
+		public static DynValue exit(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			DynValue v_exitCode = args.AsType(0, "exit", DataType.Number, true);
+			int exitCode = 0;
+
+			if (v_exitCode.IsNotNil())
+				exitCode = (int)v_exitCode.Number;
+
+			Environment.Exit(exitCode);
+
+			throw new InvalidOperationException("Unreachable code.. reached.");
+		}
+
+		[MoonSharpMethod]
+		public static DynValue getenv(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			DynValue varName = args.AsType(0, "getenv", DataType.String, false);
+
+			string val = Environment.GetEnvironmentVariable(varName.String);
+
+			if (val == null)
+				return DynValue.Nil;
+			else
+				return DynValue.NewString(val);
+		}
+
+		[MoonSharpMethod]
+		public static DynValue remove(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			string fileName = args.AsType(0, "remove", DataType.String, false).String;
+
+			try
+			{
+				if (File.Exists(fileName))
+				{
+					File.Delete(fileName);
+					return DynValue.True;
+				}
+				else
+				{
+					return DynValue.NewTuple(DynValue.Nil, DynValue.NewString("file not found."), DynValue.NewNumber(-1));
+				}
+			}
+			catch (Exception ex)
+			{
+				return DynValue.NewTuple(DynValue.Nil, DynValue.NewString(ex.Message), DynValue.NewNumber(-1));
+			}
+		}
+
+		[MoonSharpMethod]
+		public static DynValue rename(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			string fileNameOld = args.AsType(0, "rename", DataType.String, false).String;
+			string fileNameNew = args.AsType(0, "rename", DataType.String, false).String;
+
+			try
+			{
+				File.Move(fileNameOld, fileNameNew);
+				return DynValue.True;
+			}
+			catch (Exception ex)
+			{
+				return DynValue.NewTuple(DynValue.Nil, DynValue.NewString(ex.Message), DynValue.NewNumber(-1));
+			}
+		}
+
+		[MoonSharpMethod]
+		public static DynValue setlocale(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			return DynValue.NewString("n/a");
+		}
+
+		[MoonSharpMethod]
+		public static DynValue tmpname(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			return DynValue.NewString(Path.GetTempFileName());
+		}
+
+	}
+}

+ 266 - 0
src/MoonSharp.Interpreter/CoreLib/OsTimeMethods.cs

@@ -0,0 +1,266 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using MoonSharp.Interpreter.Execution;
+
+namespace MoonSharp.Interpreter.CoreLib
+{
+	[MoonSharpModule(Namespace = "os")]
+	public class OsTimeMethods
+	{
+		static DateTime Time0 = DateTime.UtcNow;
+		static DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
+
+		private static DynValue GetUnixTime(DateTime dateTime, DateTime? epoch = null)
+		{
+			return DynValue.NewNumber((dateTime - (epoch ?? Epoch)).TotalSeconds);
+		}
+
+		private static DateTime FromUnixTime(double unixtime)
+		{
+			TimeSpan ts = TimeSpan.FromSeconds(unixtime);
+			return Epoch + ts;
+		}
+
+		[MoonSharpMethod]
+		public static DynValue clock(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			return GetUnixTime(DateTime.UtcNow, Time0);
+		}
+
+		[MoonSharpMethod]
+		public static DynValue difftime(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			DynValue t2 = args.AsType(0, "difftime", DataType.Number, false);
+			DynValue t1 = args.AsType(1, "difftime", DataType.Number, true);
+
+			if (t1.IsNil())
+				return DynValue.NewNumber(t2.Number);
+
+			return DynValue.NewNumber(t2.Number - t1.Number);
+		}
+
+		[MoonSharpMethod]
+		public static DynValue time(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			DateTime date = DateTime.UtcNow;
+
+			if (args.Count > 0)
+			{
+				Table t = args.AsType(0, "time", DataType.Table, false).Table;
+				date = ParseTimeTable(t);
+			}
+
+			return GetUnixTime(date);
+		}
+
+		static DateTime ParseTimeTable(Table t)
+		{
+			int sec = GetTimeTableField(t, "sec") ?? 0;
+			int min = GetTimeTableField(t, "min") ?? 0;
+			int hour = GetTimeTableField(t, "hour") ?? 12;
+			int? day = GetTimeTableField(t, "day");
+			int? month = GetTimeTableField(t, "month");
+			int? year = GetTimeTableField(t, "year");
+
+			if (day == null)
+				throw new ScriptRuntimeException("field 'day' missing in date table");
+
+			if (month == null)
+				throw new ScriptRuntimeException("field 'month' missing in date table");
+
+			if (year == null)
+				throw new ScriptRuntimeException("field 'year' missing in date table");
+
+			return new DateTime(year.Value, month.Value, day.Value, hour, min, sec);
+		}
+
+
+		private static int? GetTimeTableField(Table t, string key)
+		{
+			DynValue v = t.Get(key);
+			double? d = v.CastToNumber();
+
+			if (d.HasValue)
+				return (int)d.Value;
+
+			return null;
+		}
+
+		[MoonSharpMethod]
+		public static DynValue date(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			DateTime reference = DateTime.UtcNow;
+
+			DynValue vformat = args.AsType(0, "date", DataType.String, true);
+			DynValue vtime = args.AsType(1, "date", DataType.Number, true);
+
+			string format = (vformat.IsNil()) ? "%c" : vformat.String;
+
+			if (vtime.IsNotNil())
+				reference = FromUnixTime(vtime.Number);
+
+			bool isDst = false;
+
+			if (format.StartsWith("!"))
+			{
+				format = format.Substring(1);
+			}
+			else
+			{
+				reference = TimeZoneInfo.ConvertTimeFromUtc(reference, TimeZoneInfo.Local);
+				isDst = reference.IsDaylightSavingTime();
+			}
+
+
+			if (format == "*t")
+			{
+				Table t = new Table(executionContext.GetScript());
+
+				t.Set("year", DynValue.NewNumber(reference.Year));
+				t.Set("month", DynValue.NewNumber(reference.Month));
+				t.Set("day", DynValue.NewNumber(reference.Day));
+				t.Set("hour", DynValue.NewNumber(reference.Hour));
+				t.Set("min", DynValue.NewNumber(reference.Minute));
+				t.Set("sec", DynValue.NewNumber(reference.Second));
+				t.Set("wday", DynValue.NewNumber(((int)reference.DayOfWeek) + 1));
+				t.Set("yday", DynValue.NewNumber(reference.DayOfYear));
+				t.Set("isdst", DynValue.NewBoolean(isDst));
+
+				return DynValue.NewTable(t);
+			}
+
+			else return DynValue.NewString(StrFTime(format, reference));
+		}
+
+		private static string StrFTime(string format, DateTime d)
+		{
+			// ref: http://www.cplusplus.com/reference/ctime/strftime/
+
+			Dictionary<char, string> STANDARD_PATTERNS = new Dictionary<char, string>()
+			{
+				{ 'a', "ddd" },
+				{ 'A', "dddd" },
+				{ 'b', "MMM" },
+				{ 'B', "MMMM" },
+				{ 'c', "%f" },
+				{ 'd', "dd" },
+				{ 'D', "MM/dd/yy" },
+				{ 'F', "yyyy-MM-dd" },
+				{ 'g', "yy" },
+				{ 'G', "yyyy" },
+				{ 'h', "MMM" },
+				{ 'H', "HH" },
+				{ 'I', "hh" },
+				{ 'm', "MM" },
+				{ 'M', "mm" },
+				{ 'p', "tt" },
+				{ 'r', "h:mm:ss tt" },
+				{ 'R', "HH:mm" },
+				{ 'S', "ss" },
+				{ 'T', "HH:mm:ss" },
+				{ 'y', "yy" },
+				{ 'Y', "yyyy" },
+				{ 'x', "d" },
+				{ 'X', "T" },
+				{ 'z', "zzz" },
+				{ 'Z', "zzz" },
+			};
+
+
+			StringBuilder sb = new StringBuilder();
+
+			bool isEscapeSequence = false;
+
+			for (int i = 0; i < format.Length; i++)
+			{
+				char c = format[i];
+
+				if (c == '%')
+				{
+					if (isEscapeSequence)
+					{
+						sb.Append('%');
+						isEscapeSequence = false;
+					}
+					else
+						isEscapeSequence = true;
+
+					continue;
+				}
+
+				if (!isEscapeSequence)
+				{
+					sb.Append(c);
+					continue;
+				}
+
+				if (c == 'O' || c == 'E') continue; // no modifiers
+
+				isEscapeSequence = false;
+
+				if (STANDARD_PATTERNS.ContainsKey(c))
+				{
+					sb.Append(d.ToString(STANDARD_PATTERNS[c]));
+				}
+				else if (c == 'e')
+				{
+					string s = d.ToString("%d");
+					if (s.Length < 2) s = " " + s;
+					sb.Append(s);
+				}
+				else if (c == 'n')
+				{
+					sb.Append('\n');
+				}
+				else if (c == 't')
+				{
+					sb.Append('\t');
+				}
+				else if (c == 'C')
+				{
+					sb.Append((int)(d.Year / 100));
+				}
+				else if (c == 'j')
+				{
+					sb.Append(d.DayOfYear.ToString("000"));
+				}
+				else if (c == 'u')
+				{
+					int weekDay = (int)d.DayOfWeek;
+					if (weekDay == 0)
+						weekDay = 7;
+
+					sb.Append(weekDay);
+				}
+				else if (c == 'w')
+				{
+					int weekDay = (int)d.DayOfWeek;
+					sb.Append(weekDay);
+				}
+				else if (c == 'U')
+				{
+					// Week number with the first Sunday as the first day of week one (00-53)
+					sb.Append("??");
+				}
+				else if (c == 'V')
+				{
+					// ISO 8601 week number (00-53)
+					sb.Append("??");
+				}
+				else if (c == 'W')
+				{
+					// Week number with the first Monday as the first day of week one (00-53)
+					sb.Append("??");
+				}
+				else
+				{
+					throw new ScriptRuntimeException("bad argument #1 to 'date' (invalid conversion specifier '{0}')", format);
+				}
+			}
+
+			return sb.ToString();
+		}
+	}
+}

+ 25 - 0
src/MoonSharp.Interpreter/DataTypes/CallbackArguments.cs

@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
+using MoonSharp.Interpreter.DataStructs;
 using MoonSharp.Interpreter.Execution;
 
 namespace MoonSharp.Interpreter
@@ -142,6 +143,20 @@ namespace MoonSharp.Interpreter
 			return this[argNum].CheckType(funcName, type, argNum, allowNil ? TypeValidationFlags.AllowNil | TypeValidationFlags.AutoConvert : TypeValidationFlags.AutoConvert);
 		}
 
+		/// <summary>
+		/// Gets the specified argument as as an argument of the specified user data type. If not possible,
+		/// an exception is raised.
+		/// </summary>
+		/// <typeparam name="T">The desired userdata type</typeparam>
+		/// <param name="argNum">The argument number.</param>
+		/// <param name="funcName">Name of the function.</param>
+		/// <param name="allowNil">if set to <c>true</c> nil values are allowed.</param>
+		/// <returns></returns>
+		public T AsUserData<T>(int argNum, string funcName, bool allowNil = false)
+		{
+			return this[argNum].CheckUserDataType<T>(funcName, argNum, allowNil ? TypeValidationFlags.AllowNil : TypeValidationFlags.None);
+		}
+
 		/// <summary>
 		/// Gets the specified argument as an integer
 		/// </summary>
@@ -183,5 +198,15 @@ namespace MoonSharp.Interpreter
 			}
 		}
 
+
+		public CallbackArguments SkipMethodCall()
+		{
+			if (this.IsMethodCall)
+			{
+				Slice<DynValue> slice = new Slice<DynValue>(m_Args, 1, m_Args.Count - 1, false);
+				return new CallbackArguments(slice, false);
+			}
+			else return this;
+		}
 	}
 }

+ 1 - 1
src/MoonSharp.Interpreter/DataTypes/DataType.cs

@@ -7,7 +7,7 @@ using System.Text;
 namespace MoonSharp.Interpreter
 {
 	/// <summary>
-	/// Enumeration of possible data types in Moon#
+	/// Enumeration of possible data types in MoonSharp
 	/// </summary>
 	public enum DataType
 	{

+ 28 - 5
src/MoonSharp.Interpreter/DataTypes/DynValue.cs

@@ -11,7 +11,7 @@ using MoonSharp.Interpreter.Execution.VM;
 namespace MoonSharp.Interpreter
 {
 	/// <summary>
-	/// A class representing a value in a Lua/Moon# script.
+	/// A class representing a value in a Lua/MoonSharp script.
 	/// </summary>
 	public sealed class DynValue
 	{
@@ -207,7 +207,7 @@ namespace MoonSharp.Interpreter
 		}
 
 		/// <summary>
-		/// Creates a new request for a tail call. This is the preferred way to execute Lua/Moon# code from a callback,
+		/// Creates a new request for a tail call. This is the preferred way to execute Lua/MoonSharp code from a callback,
 		/// although it's not always possible to use it. When a function (callback or script closure) returns a
 		/// TailCallRequest, the bytecode processor immediately executes the function contained in the request.
 		/// By executing script in this way, a callback function ensures it's not on the stack anymore and thus a number
@@ -230,7 +230,7 @@ namespace MoonSharp.Interpreter
 		}
 
 		/// <summary>
-		/// Creates a new request for a tail call. This is the preferred way to execute Lua/Moon# code from a callback,
+		/// Creates a new request for a tail call. This is the preferred way to execute Lua/MoonSharp code from a callback,
 		/// although it's not always possible to use it. When a function (callback or script closure) returns a
 		/// TailCallRequest, the bytecode processor immediately executes the function contained in the request.
 		/// By executing script in this way, a callback function ensures it's not on the stack anymore and thus a number
@@ -735,7 +735,7 @@ namespace MoonSharp.Interpreter
 		}
 
 		/// <summary>
-		/// Converts this Moon# DynValue to a CLR object.
+		/// Converts this MoonSharp DynValue to a CLR object.
 		/// </summary>
 		public object ToObject()
 		{
@@ -743,7 +743,7 @@ namespace MoonSharp.Interpreter
 		}
 
 		/// <summary>
-		/// Converts this Moon# DynValue to a CLR object of the specified type.
+		/// Converts this MoonSharp DynValue to a CLR object of the specified type.
 		/// </summary>
 		public T ToObject<T>()
 		{
@@ -801,6 +801,29 @@ namespace MoonSharp.Interpreter
 			throw ScriptRuntimeException.BadArgument(argNum, funcName, desiredType, this.Type, allowNil);
 		}
 
+		/// <summary>
+		/// Checks if the type is a specific userdata type, and returns it or throws.
+		/// </summary>
+		/// <typeparam name="T"></typeparam>
+		/// <param name="funcName">Name of the function.</param>
+		/// <param name="argNum">The argument number.</param>
+		/// <param name="flags">The flags.</param>
+		/// <returns></returns>
+		public T CheckUserDataType<T>(string funcName, int argNum = -1, TypeValidationFlags flags = TypeValidationFlags.Default)
+		{
+			DynValue v = this.CheckType(funcName, DataType.UserData, argNum, flags);
+			bool allowNil = ((int)(flags & TypeValidationFlags.AllowNil) != 0);
+
+			if (v.IsNil())
+				return default(T);
+
+			object o = v.UserData.Object;
+			if (o != null && o is T)
+				return (T)o;
+
+			throw ScriptRuntimeException.BadArgumentUserData(argNum, funcName, typeof(T), o, allowNil);
+		}
+
 
 	}
 

+ 1 - 1
src/MoonSharp.Interpreter/DataTypes/InteropAccessMode.cs

@@ -6,7 +6,7 @@ using System.Text;
 namespace MoonSharp.Interpreter
 {
 	/// <summary>
-	/// Enumerations of the possible strategies to marshal CLR objects to Moon# userdata and functions.
+	/// Enumerations of the possible strategies to marshal CLR objects to MoonSharp userdata and functions.
 	/// See also : <seealso cref="CallbackFunction"/> and <seealso cref="UserData"/> .
 	/// </summary>
 	public enum InteropAccessMode

+ 1 - 1
src/MoonSharp.Interpreter/DataTypes/Table.cs

@@ -58,7 +58,7 @@ namespace MoonSharp.Interpreter
 
 		/// <summary>
 		/// Gets or sets the <see cref="System.Object"/> with the specified key.
-		/// This will marshall CLR and Moon# objects in the best possible way.
+		/// This will marshall CLR and MoonSharp objects in the best possible way.
 		/// </summary>
 		/// <value>
 		/// The <see cref="System.Object"/>.

+ 4 - 0
src/MoonSharp.Interpreter/DataTypes/TypeValidationFlags.cs

@@ -12,6 +12,10 @@ namespace MoonSharp.Interpreter
 	[Flags]
 	public enum TypeValidationFlags
 	{
+		/// <summary>
+		/// No type validation specific behaviour
+		/// </summary>
+		None  = 0,
 		/// <summary>
 		/// Nil and Void values are allowed (and returned by the call)
 		/// </summary>

+ 1 - 1
src/MoonSharp.Interpreter/DataTypes/WellKnownSymbols.cs

@@ -6,7 +6,7 @@ using System.Text;
 namespace MoonSharp.Interpreter
 {
 	/// <summary>
-	/// Constants of well known "symbols" in the Moon# grammar
+	/// Constants of well known "symbols" in the MoonSharp grammar
 	/// </summary>
 	public static class WellKnownSymbols
 	{

+ 12 - 1
src/MoonSharp.Interpreter/Errors/ScriptRuntimeException.cs

@@ -63,6 +63,17 @@ namespace MoonSharp.Interpreter
 			return new ScriptRuntimeException("bad argument #{0} to '{1}' ({2})", argNum + 1, funcName, message);
 		}
 
+		public static ScriptRuntimeException BadArgumentUserData(int argNum, string funcName, Type expected, object got, bool allowNil)
+		{
+			return new ScriptRuntimeException("bad argument #{0} to '{1}' (userdata<{2}>{3} expected, got {4})", 
+				argNum + 1, 
+				funcName,
+				expected.Name,
+				allowNil ? "nil or " : "",
+				got != null ? "userdata<" + got.GetType().Name + ">" : "null"
+				);
+		}
+
 		public static ScriptRuntimeException BadArgument(int argNum, string funcName, DataType expected, DataType got, bool allowNil)
 		{
 			return BadArgument(argNum, funcName, expected.ToErrorTypeString(), got.ToErrorTypeString(), allowNil);
@@ -155,7 +166,7 @@ namespace MoonSharp.Interpreter
 
 		public static ScriptRuntimeException UserDataArgumentTypeMismatch(DataType t, Type clrType)
 		{
-			return new ScriptRuntimeException("cannot find a conversion from a moon# {0} to a clr {1}", t.ToString().ToLowerInvariant(), clrType.FullName);
+			return new ScriptRuntimeException("cannot find a conversion from a MoonSharp {0} to a clr {1}", t.ToString().ToLowerInvariant(), clrType.FullName);
 		}
 
 		public static ScriptRuntimeException UserDataMissingField(string typename, string fieldname)

+ 15 - 0
src/MoonSharp.Interpreter/Execution/ScriptExecutionContext.cs

@@ -204,5 +204,20 @@ namespace MoonSharp.Interpreter.Execution
 		{
 			return m_Processor.FindSymbolByName(symbol);
 		}
+
+		/// <summary>
+		/// Gets the current global env, or null if not found.
+		/// </summary>
+		public Table CurrentGlobalEnv
+		{
+			get
+			{
+				DynValue env = EvaluateSymbolByName(WellKnownSymbols.ENV);
+
+				if (env == null || env.Type != DataType.Table)
+					return null;
+				else return env.Table;
+			}
+		}
 	}
 }

+ 1 - 1
src/MoonSharp.Interpreter/Execution/VM/OpCode.cs

@@ -33,7 +33,7 @@ namespace MoonSharp.Interpreter.Execution.VM
 		Exit,		// Leaves every stack frame up and including the topmost function frame, plus it exits the topmost closure
 		BeginFn,	// Adjusts for start of function, taking in parameters and allocating locals
 		Args,		// Takes the arguments passed to a function and sets the appropriate symbols in the local scope
-		Call,		// Calls the function specified on the specified element from the top of the v-stack. If the function is a Moon# function, it pushes its numeric value on the v-stack, then pushes the current PC onto the x-stack, enters the function closure and jumps to the function first instruction. If the function is a CLR function, it pops the function value from the v-stack, then invokes the function synchronously and finally pushes the result on the v-stack.
+		Call,		// Calls the function specified on the specified element from the top of the v-stack. If the function is a MoonSharp function, it pushes its numeric value on the v-stack, then pushes the current PC onto the x-stack, enters the function closure and jumps to the function first instruction. If the function is a CLR function, it pops the function value from the v-stack, then invokes the function synchronously and finally pushes the result on the v-stack.
 		ThisCall,	// Same as call, but the call is a ':' method invocation
 		Ret,		// Pops the top n values of the v-stack. Then pops an X value from the v-stack. Then pops X values from the v-stack. Afterwards, it pushes the top n values popped in the first step, pops the top of the x-stack and jumps to that location.
 

+ 1 - 1
src/MoonSharp.Interpreter/Execution/VM/Processor/Processor_InstructionLoop.cs

@@ -405,7 +405,7 @@ namespace MoonSharp.Interpreter.Execution.VM
 			DynValue s = v.Tuple.Length >= 2 ? v.Tuple[1] : DynValue.Nil;
 			DynValue var = v.Tuple.Length >= 3 ? v.Tuple[2] : DynValue.Nil;
 
-			// Moon# additions - given f, s, var
+			// MoonSharp additions - given f, s, var
 			// 1) if f is not a function and has a __iterator metamethod, call __iterator to get the triplet
 			// 2) if f is a table with no __call metamethod, use a default table iterator
 

+ 5 - 1
src/MoonSharp.Interpreter/Interop/UserDataMethodDescriptor.cs

@@ -33,7 +33,7 @@ namespace MoonSharp.Interpreter.Interop
 			m_IsAction = mi.ReturnType == typeof(void);
 
 			m_Arguments = mi.GetParameters().Select(pi => pi.ParameterType).ToArray();
-			m_Defaults = mi.GetParameters().Select(pi => pi.DefaultValue).ToArray(); 
+			m_Defaults = mi.GetParameters().Select(pi => pi.DefaultValue).ToArray();
 
 			if (AccessMode == InteropAccessMode.Preoptimized)
 				Optimize();
@@ -64,6 +64,10 @@ namespace MoonSharp.Interpreter.Interop
 				{
 					pars[i] = context;
 				}
+				else if (m_Arguments[i] == typeof(CallbackArguments))
+				{
+					pars[i] = args.SkipMethodCall();
+				}
 				else
 				{
 					var arg = args.RawGet(j, false) ?? DynValue.Void;

+ 3 - 2
src/MoonSharp.Interpreter/Loaders/ClassicLuaScriptLoader.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.IO;
 using System.Linq;
 using System.Text;
+using MoonSharp.Interpreter.RuntimeAbstraction;
 
 namespace MoonSharp.Interpreter.Loaders
 {
@@ -12,12 +13,12 @@ namespace MoonSharp.Interpreter.Loaders
 		
 		public ClassicLuaScriptLoader()
 		{
-			string env = Environment.GetEnvironmentVariable("MOONSHARP_PATH");
+			string env = Platform.Current.GetEnvironmentVariable("MOONSHARP_PATH");
 			if (!string.IsNullOrEmpty(env)) m_EnvironmentPaths = UnpackStringPaths(env);
 
 			if (m_EnvironmentPaths == null)
 			{
-				env = Environment.GetEnvironmentVariable("LUA_PATH");
+				env = Platform.Current.GetEnvironmentVariable("LUA_PATH");
 				if (!string.IsNullOrEmpty(env)) m_EnvironmentPaths = UnpackStringPaths(env);
 			}
 

+ 6 - 7
src/MoonSharp.Interpreter/Modules/CoreModules.cs

@@ -21,17 +21,16 @@ namespace MoonSharp.Interpreter
 		Math = 0x100,
 		Coroutine = 0x200,
 		Bit32 = 0x400,
-		Os_Time = 0x800,
-		Os_System = 0x1000,
-		File = 0x2000,
-		Io = 0x4000,
+		OS_Time = 0x800,
+		OS_System = 0x1000,
+		__RESERVED1__ = 0x2000,
+		IO = 0x4000,
 		Dynamic = 0x8000,
 
 
-
 		Preset_HardSandbox = GlobalConsts | TableIterators | String | Table | Basic | Math | Bit32,
-		Preset_SoftSandbox = Preset_HardSandbox | Metatables | ErrorHandling | Coroutine | Os_Time | Dynamic,
-		Preset_Default = Preset_SoftSandbox | LoadMethods | Os_System | File | Io,
+		Preset_SoftSandbox = Preset_HardSandbox | Metatables | ErrorHandling | Coroutine | OS_Time | Dynamic,
+		Preset_Default = Preset_SoftSandbox | LoadMethods | OS_System | IO,
 		Preset_Complete = Preset_Default,
 
 	}

+ 17 - 2
src/MoonSharp.Interpreter/Modules/ModuleRegister.cs

@@ -26,6 +26,9 @@ namespace MoonSharp.Interpreter
 			if (modules.Has(CoreModules.Coroutine)) RegisterModuleType<CoroutineMethods>(table);
 			if (modules.Has(CoreModules.Bit32)) RegisterModuleType<Bit32Module>(table);
 			if (modules.Has(CoreModules.Dynamic)) RegisterModuleType<DynamicModule>(table);
+			if (modules.Has(CoreModules.OS_System)) RegisterModuleType<OsSystemMethods>(table);
+			if (modules.Has(CoreModules.OS_Time)) RegisterModuleType<OsTimeMethods>(table);
+			if (modules.Has(CoreModules.IO)) RegisterModuleType<IoMethods>(table);
 
 			return table;
 		}
@@ -131,8 +134,20 @@ namespace MoonSharp.Interpreter
 			}
 			else
 			{
-				Table table = new Table(gtable.OwnerScript);
-				gtable.Set(attr.Namespace, DynValue.NewTable(table));
+				Table table = null;
+
+				DynValue found = gtable.Get(attr.Namespace);
+
+				if (found.Type == DataType.Table)
+				{
+					table = found.Table;
+				}
+				else
+				{
+					table = new Table(gtable.OwnerScript);
+					gtable.Set(attr.Namespace, DynValue.NewTable(table));
+				}
+
 
 				DynValue package = gtable.RawGet("package");
 

+ 14 - 1
src/MoonSharp.Interpreter/MoonSharp.Interpreter.csproj

@@ -82,11 +82,16 @@
     <Compile Include="CoreLib\BasicMethods.cs" />
     <Compile Include="CoreLib\DynamicModule.cs" />
     <Compile Include="CoreLib\ErrorHandling.cs" />
+    <Compile Include="CoreLib\IO\BinaryEncoding.cs" />
+    <Compile Include="CoreLib\IO\FileUserData.cs" />
+    <Compile Include="CoreLib\IoMethods.cs" />
+    <Compile Include="CoreLib\IO\FileUserDataBase.cs" />
     <Compile Include="CoreLib\LoadMethods.cs" />
     <Compile Include="CoreLib\Bit32Module.cs" />
     <Compile Include="CoreLib\MathModule.cs" />
     <Compile Include="CoreLib\MetaTableMethods.cs" />
-    <Compile Include="CoreLib\OsMethods.cs" />
+    <Compile Include="CoreLib\OsSystemMethods.cs" />
+    <Compile Include="CoreLib\OsTimeMethods.cs" />
     <Compile Include="CoreLib\StringLib\CaptureInfo.cs">
       <SubType>Code</SubType>
     </Compile>
@@ -192,6 +197,14 @@
     <Compile Include="Execution\ScriptLoadingContext.cs" />
     <Compile Include="DataTypes\DataType.cs" />
     <Compile Include="Modules\MoonSharpConstantAttribute.cs" />
+    <Compile Include="RuntimeAbstraction\PlatformImplementations\Clr2Platform.cs" />
+    <Compile Include="RuntimeAbstraction\PlatformImplementations\Clr4Platform.cs" />
+    <Compile Include="RuntimeAbstraction\Platform.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="RuntimeAbstraction\PlatformImplementations\MonoPlatform.cs" />
+    <Compile Include="RuntimeAbstraction\PlatformImplementations\UnityPlatform.cs" />
+    <Compile Include="RuntimeAbstraction\PlatformImplementations\UnityWebPlatform.cs" />
     <Compile Include="Script.cs" />
     <Compile Include="DataTypes\Table.cs" />
     <Compile Include="Execution\VM\ByteCode.cs" />

+ 64 - 0
src/MoonSharp.Interpreter/RuntimeAbstraction/Platform.cs

@@ -0,0 +1,64 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+
+namespace MoonSharp.Interpreter.RuntimeAbstraction
+{
+	public abstract class Platform
+	{
+		private static Platform s_Current;
+
+		static Platform()
+		{
+			bool onUnity = AppDomain.CurrentDomain
+				.GetAssemblies()
+				.SelectMany(a => a.GetTypes())
+				.Any(t => t.FullName.StartsWith("UnityEngine."));
+
+			if (Type.GetType("Mono.Runtime") != null)
+			{
+				if (onUnity)
+				{
+					s_Current = new UnityPlatform();
+				}
+				else
+				{
+					s_Current = new MonoPlatform();
+				}
+			}
+			else if (onUnity)
+			{
+				s_Current = new UnityWebPlatform();
+			}
+			else if (Type.GetType("System.Lazy`1") != null)
+			{
+				s_Current = new Clr4Platform();
+			}
+			else
+			{
+				s_Current = new Clr2Platform();
+			}
+
+			System.Diagnostics.Debug.WriteLine(string.Format("MoonSharp {0} running over {1}.",
+				Assembly.GetExecutingAssembly().GetName().Version,
+				s_Current.Name));
+		}
+
+
+		public static Platform Current
+		{
+			get { return s_Current; }
+		}
+
+
+		public abstract string Name { get; }
+		public abstract string GetEnvironmentVariable(string variable);
+
+
+
+
+
+	}
+}

+ 20 - 0
src/MoonSharp.Interpreter/RuntimeAbstraction/PlatformImplementations/Clr2Platform.cs

@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace MoonSharp.Interpreter.RuntimeAbstraction
+{
+	class Clr2Platform : Platform
+	{
+		public override string Name
+		{
+			get { return "Clr2"; }
+		}
+
+		public override string GetEnvironmentVariable(string variable)
+		{
+			return Environment.GetEnvironmentVariable(variable);
+		}
+	}
+}

+ 15 - 0
src/MoonSharp.Interpreter/RuntimeAbstraction/PlatformImplementations/Clr4Platform.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace MoonSharp.Interpreter.RuntimeAbstraction
+{
+	class Clr4Platform : Clr2Platform
+	{
+		public override string Name
+		{
+			get { return "Clr4"; }
+		}
+	}
+}

+ 15 - 0
src/MoonSharp.Interpreter/RuntimeAbstraction/PlatformImplementations/MonoPlatform.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace MoonSharp.Interpreter.RuntimeAbstraction
+{
+	class MonoPlatform : Clr2Platform
+	{
+		public override string Name
+		{
+			get { return "Mono"; }
+		}
+	}
+}

+ 15 - 0
src/MoonSharp.Interpreter/RuntimeAbstraction/PlatformImplementations/UnityPlatform.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace MoonSharp.Interpreter.RuntimeAbstraction
+{
+	class UnityPlatform : MonoPlatform
+	{
+		public override string Name
+		{
+			get { return "Unity"; }
+		}
+	}
+}

+ 21 - 0
src/MoonSharp.Interpreter/RuntimeAbstraction/PlatformImplementations/UnityWebPlatform.cs

@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace MoonSharp.Interpreter.RuntimeAbstraction
+{
+	class UnityWebPlatform : UnityPlatform
+	{
+		public override string Name
+		{
+			get { return "UnityWeb"; }
+		}
+
+		public override string GetEnvironmentVariable(string variable)
+		{
+			return null;
+		}
+
+	}
+}

+ 32 - 13
src/MoonSharp.Interpreter/Script.cs

@@ -18,7 +18,7 @@ using MoonSharp.Interpreter.Tree.Statements;
 namespace MoonSharp.Interpreter
 {
 	/// <summary>
-	/// This class implements a Moon# scripting session. Multiple Script objects can coexist in the same program but cannot share
+	/// This class implements a MoonSharp scripting session. Multiple Script objects can coexist in the same program but cannot share
 	/// data among themselves unless some mechanism is put in place.
 	/// </summary>
 	public class Script
@@ -32,6 +32,7 @@ namespace MoonSharp.Interpreter
 		Table[] m_TypeMetatables = new Table[(int)LuaTypeExtensions.MaxMetaTypes];
 
 
+	
 		static Script()
 		{
 			DefaultScriptLoader = new ClassicLuaScriptLoader();
@@ -53,6 +54,7 @@ namespace MoonSharp.Interpreter
 		public Script(CoreModules coreModules)
 		{
 			PerformanceStats = new PerformanceStatistics();
+			Registry = new Table(this);
 
 			DebugPrint = s => { Console.WriteLine(s); };
 			m_ByteCode = new ByteCode();
@@ -96,7 +98,7 @@ namespace MoonSharp.Interpreter
 		}
 
 		/// <summary>
-		/// Loads a string containing a Lua/Moon# function.
+		/// Loads a string containing a Lua/MoonSharp function.
 		/// </summary>
 		/// <param name="code">The code.</param>
 		/// <param name="globalTable">The global table to bind to this chunk.</param>
@@ -138,7 +140,7 @@ namespace MoonSharp.Interpreter
 
 
 		/// <summary>
-		/// Loads a string containing a Lua/Moon# script.
+		/// Loads a string containing a Lua/MoonSharp script.
 		/// </summary>
 		/// <param name="code">The code.</param>
 		/// <param name="globalTable">The global table to bind to this chunk.</param>
@@ -166,7 +168,7 @@ namespace MoonSharp.Interpreter
 		}
 
 		/// <summary>
-		/// Loads a string containing a Lua/Moon# script.
+		/// Loads a string containing a Lua/MoonSharp script.
 		/// </summary>
 		/// <param name="filename">The code.</param>
 		/// <param name="globalContext">The global table to bind to this chunk.</param>
@@ -191,7 +193,7 @@ namespace MoonSharp.Interpreter
 		}
 
 		/// <summary>
-		/// Loads and executes a string containing a Lua/Moon# script.
+		/// Loads and executes a string containing a Lua/MoonSharp script.
 		/// </summary>
 		/// <param name="code">The code.</param>
 		/// <param name="globalContext">The global context.</param>
@@ -205,7 +207,7 @@ namespace MoonSharp.Interpreter
 		}
 
 		/// <summary>
-		/// Loads and executes a file containing a Lua/Moon# script.
+		/// Loads and executes a file containing a Lua/MoonSharp script.
 		/// </summary>
 		/// <param name="filename">The filename.</param>
 		/// <param name="globalContext">The global context.</param>
@@ -233,7 +235,7 @@ namespace MoonSharp.Interpreter
 		/// <summary>
 		/// Runs the specified code with all possible defaults for quick experimenting.
 		/// </summary>
-		/// <param name="code">The Lua/Moon# code.</param>
+		/// <param name="code">The Lua/MoonSharp code.</param>
 		/// A DynValue containing the result of the processing of the executed script.
 		public static DynValue RunString(string code)
 		{
@@ -258,7 +260,7 @@ namespace MoonSharp.Interpreter
 		/// <summary>
 		/// Calls the specified function.
 		/// </summary>
-		/// <param name="function">The Lua/Moon# function to be called - callbacks are not supported.</param>
+		/// <param name="function">The Lua/MoonSharp function to be called - callbacks are not supported.</param>
 		/// <returns>
 		/// The return value(s) of the function call.
 		/// </returns>
@@ -274,7 +276,7 @@ namespace MoonSharp.Interpreter
 		/// <summary>
 		/// Calls the specified function.
 		/// </summary>
-		/// <param name="function">The Lua/Moon# function to be called - callbacks are not supported.</param>
+		/// <param name="function">The Lua/MoonSharp function to be called - callbacks are not supported.</param>
 		/// <param name="args">The arguments to pass to the function.</param>
 		/// <returns>
 		/// The return value(s) of the function call.
@@ -291,7 +293,7 @@ namespace MoonSharp.Interpreter
 		/// <summary>
 		/// Calls the specified function.
 		/// </summary>
-		/// <param name="function">The Lua/Moon# function to be called - callbacks are not supported.</param>
+		/// <param name="function">The Lua/MoonSharp function to be called - callbacks are not supported.</param>
 		/// <param name="args">The arguments to pass to the function.</param>
 		/// <returns>
 		/// The return value(s) of the function call.
@@ -313,7 +315,7 @@ namespace MoonSharp.Interpreter
 		/// <summary>
 		/// Calls the specified function.
 		/// </summary>
-		/// <param name="function">The Lua/Moon# function to be called - callbacks are not supported.</param>
+		/// <param name="function">The Lua/MoonSharp function to be called - callbacks are not supported.</param>
 		/// <returns></returns>
 		/// <exception cref="System.ArgumentException">Thrown if function is not of DataType.Function</exception>
 		public DynValue Call(object function)
@@ -324,7 +326,7 @@ namespace MoonSharp.Interpreter
 		/// <summary>
 		/// Calls the specified function.
 		/// </summary>
-		/// <param name="function">The Lua/Moon# function to be called - callbacks are not supported.</param>
+		/// <param name="function">The Lua/MoonSharp function to be called - callbacks are not supported.</param>
 		/// <param name="args">The arguments to pass to the function.</param>
 		/// <returns></returns>
 		/// <exception cref="System.ArgumentException">Thrown if function is not of DataType.Function</exception>
@@ -486,7 +488,7 @@ namespace MoonSharp.Interpreter
 
 
 		/// <summary>
-		/// Warms up the parser/lexer structures so that Moon# operations start faster.
+		/// Warms up the parser/lexer structures so that MoonSharp operations start faster.
 		/// </summary>
 		public static void WarmUp()
 		{
@@ -522,5 +524,22 @@ namespace MoonSharp.Interpreter
 		{
 			return new ScriptExecutionContext(m_MainProcessor, null);
 		}
+
+		/// <summary>
+		/// MoonSharp (like Lua itself) provides a registry, a predefined table that can be used by any CLR code to 
+		/// store whatever Lua values it needs to store. 
+		/// Any CLR code can store data into this table, but it should take care to choose keys 
+		/// that are different from those used by other libraries, to avoid collisions. 
+		/// Typically, you should use as key a string GUID, a string containing your library name, or a 
+		/// userdata with the address of a CLR object in your code.
+		/// </summary>
+		public Table Registry
+		{
+			get;
+			private set;
+		}
+
+
+
 	}
 }

+ 1 - 1
src/MoonSharp/Program.cs

@@ -32,7 +32,7 @@ namespace MoonSharp
 		[STAThread]
 		static void Main(string[] args)
 		{
-			Console.WriteLine("Moon# {0}\nCopyright (C) 2014 Marco Mastropaolo\nhttp://www.moonsharp.org",
+			Console.WriteLine("MoonSharp REPL {0}\nCopyright (C) 2014 Marco Mastropaolo\nhttp://www.moonsharp.org",
 				Assembly.GetAssembly(typeof(Script)).GetName().Version);
 
 			Console.WriteLine("Based on Lua 5.1 - 5.3, Copyright (C) 1994-2014 Lua.org");

+ 1 - 1
src/MoonSharpTests/Program.cs

@@ -23,7 +23,7 @@ namespace MoonSharpTests
 			int fail = 0;
 			int total = 0;
 
-			Console.WriteLine("Moon# Test Suite Runner");
+			Console.WriteLine("MoonSharp Test Suite Runner");
 			Console.WriteLine("Copyright (C) 2014 Marco Mastropaolo [http://www.mastropaolo.com]");
 			Console.WriteLine("See : http://moonsharp.codeplex.com");
 			Console.WriteLine();

+ 2 - 2
src/PerformanceComparison/Program.cs

@@ -159,7 +159,7 @@ end
 			}
 			sw.Stop();
 
-			Console.WriteLine("Moon# : {0} ms", sw.ElapsedMilliseconds);
+			Console.WriteLine("MoonSharp : {0} ms", sw.ElapsedMilliseconds);
 
 
 			lua.RegisterFunction("print", typeof(Program).GetMethod("NPrint"));
@@ -183,7 +183,7 @@ end
 
 			Console.WriteLine("M# == NL ? {0}", g_MoonSharpStr.ToString() == g_NLuaStr.ToString());
 
-			Console.WriteLine("=== Moon# ===");
+			Console.WriteLine("=== MoonSharp ===");
 			//Console.WriteLine(g_MoonSharpStr.ToString());
 			Console.WriteLine("");
 			Console.WriteLine("=== NLua  ===");

+ 0 - 3
src/moonsharp.sln

@@ -94,7 +94,4 @@ Global
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
 	EndGlobalSection
-	GlobalSection(Performance) = preSolution
-		HasPerformanceSessions = true
-	EndGlobalSection
 EndGlobal