Xanathar 10 years ago
parent
commit
0f6337283b
67 changed files with 889 additions and 300 deletions
  1. 2 3
      src/DevTools/MoonSharp.VmDebugger/ValueBrowser.cs
  2. 4 4
      src/MoonSharp.Interpreter.Tests/EndToEnd/UserDataMethodsTests.cs
  3. 8 8
      src/MoonSharp.Interpreter/CoreLib/BasicModule.cs
  4. 12 12
      src/MoonSharp.Interpreter/CoreLib/Bit32Module.cs
  5. 6 6
      src/MoonSharp.Interpreter/CoreLib/CoroutineModule.cs
  6. 10 10
      src/MoonSharp.Interpreter/CoreLib/DebugModule.cs
  7. 2 2
      src/MoonSharp.Interpreter/CoreLib/DynamicModule.cs
  8. 2 2
      src/MoonSharp.Interpreter/CoreLib/ErrorHandlingModule.cs
  9. 10 10
      src/MoonSharp.Interpreter/CoreLib/IoModule.cs
  10. 7 7
      src/MoonSharp.Interpreter/CoreLib/LoadModule.cs
  11. 29 29
      src/MoonSharp.Interpreter/CoreLib/MathModule.cs
  12. 6 6
      src/MoonSharp.Interpreter/CoreLib/MetaTableModule.cs
  13. 7 7
      src/MoonSharp.Interpreter/CoreLib/OsSystemModule.cs
  14. 4 4
      src/MoonSharp.Interpreter/CoreLib/OsTimeModule.cs
  15. 1 1
      src/MoonSharp.Interpreter/CoreLib/StringLib/KopiLua_StrLib.cs
  16. 15 15
      src/MoonSharp.Interpreter/CoreLib/StringModule.cs
  17. 3 3
      src/MoonSharp.Interpreter/CoreLib/TableIteratorsModule.cs
  18. 11 8
      src/MoonSharp.Interpreter/CoreLib/TableModule.cs
  19. 67 4
      src/MoonSharp.Interpreter/DataTypes/Closure.cs
  20. 72 0
      src/MoonSharp.Interpreter/Debugging/DebuggerAction.cs
  21. 24 0
      src/MoonSharp.Interpreter/Debugging/SourceCode.cs
  22. 0 13
      src/MoonSharp.Interpreter/Debugging/SourceCodeType.cs
  23. 54 3
      src/MoonSharp.Interpreter/Debugging/SourceRef.cs
  24. 36 0
      src/MoonSharp.Interpreter/Debugging/WatchItem.cs
  25. 18 0
      src/MoonSharp.Interpreter/Debugging/WatchType.cs
  26. 1 1
      src/MoonSharp.Interpreter/Diagnostics/PerformanceCounters/IPerformanceStopwatch.cs
  27. 2 0
      src/MoonSharp.Interpreter/Execution/InstructionFieldUsage.cs
  28. 1 34
      src/MoonSharp.Interpreter/Execution/Scopes/ClosureContext.cs
  29. 1 1
      src/MoonSharp.Interpreter/Execution/ScriptExecutionContext.cs
  30. 4 4
      src/MoonSharp.Interpreter/Execution/VM/ByteCode.cs
  31. 2 0
      src/MoonSharp.Interpreter/Execution/VM/OpCode.cs
  32. 1 1
      src/MoonSharp.Interpreter/Execution/VM/Processor/Processor_BinaryDump.cs
  33. 7 2
      src/MoonSharp.Interpreter/Execution/VM/Processor/Processor_InstructionLoop.cs
  34. 7 1
      src/MoonSharp.Interpreter/Interop/Attributes/MoonSharpUserDataAttribute.cs
  35. 7 0
      src/MoonSharp.Interpreter/Interop/Attributes/MoonSharpVisibleAttribute.cs
  36. 48 0
      src/MoonSharp.Interpreter/Interop/Converters/ConversionHelper.cs
  37. 20 0
      src/MoonSharp.Interpreter/Interop/Converters/LinqHelpers.cs
  38. 41 2
      src/MoonSharp.Interpreter/Interop/IUserDataDescriptor.cs
  39. 29 2
      src/MoonSharp.Interpreter/Interop/IUserDataType.cs
  40. 3 0
      src/MoonSharp.Interpreter/Interop/InteropAccessMode.cs
  41. 8 0
      src/MoonSharp.Interpreter/Interop/PredefinedUserData/AnonWrapper.cs
  42. 3 0
      src/MoonSharp.Interpreter/Interop/PredefinedUserData/EnumerableWrapper.cs
  43. 4 4
      src/MoonSharp.Interpreter/Interop/StandardDescriptors/AutoDescribingUserDataDescriptor.cs
  44. 4 4
      src/MoonSharp.Interpreter/Interop/StandardDescriptors/CompositeUserDataDescriptor.cs
  45. 78 2
      src/MoonSharp.Interpreter/Interop/StandardDescriptors/StandardUserDataDescriptor.cs
  46. 66 9
      src/MoonSharp.Interpreter/Interop/StandardDescriptors/StandardUserDataMethodDescriptor.cs
  47. 3 0
      src/MoonSharp.Interpreter/Interop/StandardDescriptors/StandardUserDataPropertyDescriptor.cs
  48. 3 0
      src/MoonSharp.Interpreter/Loaders/ScriptLoaderBase.cs
  49. 4 1
      src/MoonSharp.Interpreter/Loaders/UnityAssetsScriptLoader.cs
  50. 1 1
      src/MoonSharp.Interpreter/Modules/CoreModules.cs
  51. 25 6
      src/MoonSharp.Interpreter/Modules/ModuleRegister.cs
  52. 0 13
      src/MoonSharp.Interpreter/Modules/MoonSharpConstantAttribute.cs
  53. 0 13
      src/MoonSharp.Interpreter/Modules/MoonSharpMethodAttribute.cs
  54. 15 0
      src/MoonSharp.Interpreter/Modules/MoonSharpModuleAttribute.cs
  55. 18 0
      src/MoonSharp.Interpreter/Modules/MoonSharpModuleConstantAttribute.cs
  56. 23 0
      src/MoonSharp.Interpreter/Modules/MoonSharpModuleMethodAttribute.cs
  57. 3 3
      src/MoonSharp.Interpreter/MoonSharp.Interpreter.net35-client.csproj
  58. 1 1
      src/MoonSharp.Interpreter/Platforms/IPlatformAccessor.cs
  59. 3 3
      src/MoonSharp.Interpreter/Script.cs
  60. 4 0
      src/MoonSharp.Interpreter/ScriptGlobalOptions.cs
  61. 1 2
      src/MoonSharp.Interpreter/Tree/Expression_.cs
  62. 1 1
      src/MoonSharp.Interpreter/Tree/Expressions/FunctionCallExpression.cs
  63. 19 5
      src/MoonSharp.Interpreter/Tree/Expressions/IndexExpression.cs
  64. 0 6
      src/MoonSharp.Interpreter/Tree/NodeBase.cs
  65. 4 7
      src/MoonSharp.Interpreter/Tree/Statements/FunctionDefinitionStatement.cs
  66. 7 7
      src/MoonSharp.Interpreter/_Projects/MoonSharp.Interpreter.net40-client/MoonSharp.Interpreter.net40-client.csproj
  67. 7 7
      src/MoonSharp.Interpreter/_Projects/MoonSharp.Interpreter.portable40/MoonSharp.Interpreter.portable40.csproj

+ 2 - 3
src/DevTools/MoonSharp.VmDebugger/ValueBrowser.cs

@@ -131,12 +131,11 @@ namespace MoonSharp.Debugger
 		private void BuildFunctionTable(DynValue V)
 		private void BuildFunctionTable(DynValue V)
 		{
 		{
 			var F = V.Function;
 			var F = V.Function;
-			var C = F.ClosureContext;
 			lvProps.Add("Bytecode Location", F.EntryPointByteCodeLocation.ToString("X8"));
 			lvProps.Add("Bytecode Location", F.EntryPointByteCodeLocation.ToString("X8"));
 
 
-			for (int i = 0; i < C.Count; i++)
+			for (int i = 0; i < F.GetUpvaluesCount(); i++)
 			{
 			{
-				lvTableData.Add(C.Symbols[i], C[i]).Tag = C[i];
+				lvTableData.Add(F.GetUpvalueName(i), F.GetUpvalue(i)).Tag = F.GetUpvalue(i);
 			}
 			}
 		}
 		}
 
 

+ 4 - 4
src/MoonSharp.Interpreter.Tests/EndToEnd/UserDataMethodsTests.cs

@@ -158,12 +158,12 @@ namespace MoonSharp.Interpreter.Tests.EndToEnd
 				get { return typeof(SomeOtherClassCustomDescriptor); }
 				get { return typeof(SomeOtherClassCustomDescriptor); }
 			}
 			}
 
 
-			public DynValue Index(Script script, object obj, DynValue index)
+			public DynValue Index(Script script, object obj, DynValue index, bool dummy)
 			{
 			{
 				return DynValue.NewNumber(index.Number * 4);
 				return DynValue.NewNumber(index.Number * 4);
 			}
 			}
 
 
-			public bool SetIndex(Script script, object obj, DynValue index, DynValue value)
+			public bool SetIndex(Script script, object obj, DynValue index, DynValue value, bool dummy)
 			{
 			{
 				throw new NotImplementedException();
 				throw new NotImplementedException();
 			}
 			}
@@ -184,12 +184,12 @@ namespace MoonSharp.Interpreter.Tests.EndToEnd
 
 
 		public class SelfDescribingClass : IUserDataType
 		public class SelfDescribingClass : IUserDataType
 		{
 		{
-			public DynValue Index(Script script, DynValue index)
+			public DynValue Index(Script script, DynValue index, bool isNameIndex)
 			{
 			{
 				return DynValue.NewNumber(index.Number * 3);
 				return DynValue.NewNumber(index.Number * 3);
 			}
 			}
 
 
-			public bool SetIndex(Script script, DynValue index, DynValue value)
+			public bool SetIndex(Script script, DynValue index, DynValue value, bool isNameIndex)
 			{
 			{
 				throw new NotImplementedException();
 				throw new NotImplementedException();
 			}
 			}

+ 8 - 8
src/MoonSharp.Interpreter/CoreLib/BasicModule.cs

@@ -17,7 +17,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		//----------------------------------------------------------------------------------------------------------------
 		//----------------------------------------------------------------------------------------------------------------
 		//Returns the type of its only argument, coded as a string. The possible results of this function are "nil" 
 		//Returns the type of its only argument, coded as a string. The possible results of this function are "nil" 
 		//(a string, not the value nil), "number", "string", "boolean", "table", "function", "thread", and "userdata". 
 		//(a string, not the value nil), "number", "string", "boolean", "table", "function", "thread", and "userdata". 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue type(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue type(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			if (args.Count < 1) throw ScriptRuntimeException.BadArgumentValueExpected(0, "type");
 			if (args.Count < 1) throw ScriptRuntimeException.BadArgumentValueExpected(0, "type");
@@ -32,7 +32,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		//----------------------------------------------------------------------------------------------------------------
 		//----------------------------------------------------------------------------------------------------------------
 		//Issues an error when the value of its argument v is false (i.e., nil or false); 
 		//Issues an error when the value of its argument v is false (i.e., nil or false); 
 		//otherwise, returns all its arguments. message is an error message; when absent, it defaults to "assertion failed!" 
 		//otherwise, returns all its arguments. message is an error message; when absent, it defaults to "assertion failed!" 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue assert(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue assert(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue v = args[0];
 			DynValue v = args[0];
@@ -52,7 +52,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		// collectgarbage  ([opt [, arg]])
 		// collectgarbage  ([opt [, arg]])
 		// ----------------------------------------------------------------------------------------------------------------
 		// ----------------------------------------------------------------------------------------------------------------
 		// This function is mostly a stub towards the CLR GC. If mode is nil, "collect" or "restart", a GC is forced.
 		// This function is mostly a stub towards the CLR GC. If mode is nil, "collect" or "restart", a GC is forced.
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue collectgarbage(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue collectgarbage(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue opt = args[0];
 			DynValue opt = args[0];
@@ -79,7 +79,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		// With level 1 (the default), the error position is where the error function was called. 
 		// With level 1 (the default), the error position is where the error function was called. 
 		// Level 2 points the error to where the function that called error was called; and so on. 
 		// Level 2 points the error to where the function that called error was called; and so on. 
 		// Passing a level 0 avoids the addition of error position information to the message. 
 		// Passing a level 0 avoids the addition of error position information to the message. 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue error(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue error(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue message = args.AsType(0, "error", DataType.String, false);
 			DynValue message = args.AsType(0, "error", DataType.String, false);
@@ -94,7 +94,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		// 
 		// 
 		// If the metatable of v has a "__tostring" field, then tostring calls the corresponding value with v as argument, 
 		// If the metatable of v has a "__tostring" field, then tostring calls the corresponding value with v as argument, 
 		// and uses the result of the call as its result. 
 		// and uses the result of the call as its result. 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue tostring(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue tostring(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			if (args.Count < 1) throw ScriptRuntimeException.BadArgumentValueExpected(0, "tostring");
 			if (args.Count < 1) throw ScriptRuntimeException.BadArgumentValueExpected(0, "tostring");
@@ -129,7 +129,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		// If index is a number, returns all arguments after argument number index; a negative number indexes from 
 		// If index is a number, returns all arguments after argument number index; a negative number indexes from 
 		// the end (-1 is the last argument). Otherwise, index must be the string "#", and select returns the total
 		// the end (-1 is the last argument). Otherwise, index must be the string "#", and select returns the total
 		// number of extra arguments it received. 
 		// number of extra arguments it received. 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue select(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue select(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			if (args[0].Type == DataType.String && args[0].String == "#")
 			if (args[0].Type == DataType.String && args[0].String == "#")
@@ -185,7 +185,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		// The base may be any integer between 2 and 36, inclusive. In bases above 10, the letter 'A' (in either 
 		// The base may be any integer between 2 and 36, inclusive. In bases above 10, the letter 'A' (in either 
 		// upper or lower case) represents 10, 'B' represents 11, and so forth, with 'Z' representing 35. If the 
 		// upper or lower case) represents 10, 'B' represents 11, and so forth, with 'Z' representing 35. If the 
 		// string e is not a valid numeral in the given base, the function returns nil. 
 		// string e is not a valid numeral in the given base, the function returns nil. 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue tonumber(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue tonumber(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			if (args.Count < 1) throw ScriptRuntimeException.BadArgumentValueExpected(0, "tonumber");
 			if (args.Count < 1) throw ScriptRuntimeException.BadArgumentValueExpected(0, "tonumber");
@@ -248,7 +248,7 @@ namespace MoonSharp.Interpreter.CoreLib
 			}
 			}
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue print(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue print(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			StringBuilder sb = new StringBuilder();
 			StringBuilder sb = new StringBuilder();

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

@@ -71,7 +71,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		}
 		}
 
 
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue extract(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue extract(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue v_v = args.AsType(0, "extract", DataType.Number);
 			DynValue v_v = args.AsType(0, "extract", DataType.Number);
@@ -90,7 +90,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		}
 		}
 
 
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue replace(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue replace(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue v_v = args.AsType(0, "replace", DataType.Number);
 			DynValue v_v = args.AsType(0, "replace", DataType.Number);
@@ -128,7 +128,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		}
 		}
 
 
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue arshift(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue arshift(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue v_v = args.AsType(0, "arshift", DataType.Number);
 			DynValue v_v = args.AsType(0, "arshift", DataType.Number);
@@ -147,7 +147,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		}
 		}
 
 
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue rshift(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue rshift(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue v_v = args.AsType(0, "rshift", DataType.Number);
 			DynValue v_v = args.AsType(0, "rshift", DataType.Number);
@@ -166,7 +166,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		}
 		}
 
 
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue lshift(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue lshift(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue v_v = args.AsType(0, "lshift", DataType.Number);
 			DynValue v_v = args.AsType(0, "lshift", DataType.Number);
@@ -184,25 +184,25 @@ namespace MoonSharp.Interpreter.CoreLib
 			return DynValue.NewNumber(v);
 			return DynValue.NewNumber(v);
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue band(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue band(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return DynValue.NewNumber(Bitwise("band", args, (x, y) => x & y));
 			return DynValue.NewNumber(Bitwise("band", args, (x, y) => x & y));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue btest(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue btest(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return DynValue.NewBoolean(0 != Bitwise("btest", args, (x, y) => x & y));
 			return DynValue.NewBoolean(0 != Bitwise("btest", args, (x, y) => x & y));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue bor(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue bor(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return DynValue.NewNumber(Bitwise("bor", args, (x, y) => x | y));
 			return DynValue.NewNumber(Bitwise("bor", args, (x, y) => x | y));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue bnot(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue bnot(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue v_v = args.AsType(0, "bnot", DataType.Number);
 			DynValue v_v = args.AsType(0, "bnot", DataType.Number);
@@ -210,13 +210,13 @@ namespace MoonSharp.Interpreter.CoreLib
 			return DynValue.NewNumber(~v);
 			return DynValue.NewNumber(~v);
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue bxor(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue bxor(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return DynValue.NewNumber(Bitwise("bxor", args, (x, y) => x ^ y));
 			return DynValue.NewNumber(Bitwise("bxor", args, (x, y) => x ^ y));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue lrotate(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue lrotate(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue v_v = args.AsType(0, "lrotate", DataType.Number);
 			DynValue v_v = args.AsType(0, "lrotate", DataType.Number);
@@ -234,7 +234,7 @@ namespace MoonSharp.Interpreter.CoreLib
 			return DynValue.NewNumber(v);
 			return DynValue.NewNumber(v);
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue rrotate(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue rrotate(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue v_v = args.AsType(0, "rrotate", DataType.Number);
 			DynValue v_v = args.AsType(0, "rrotate", DataType.Number);

+ 6 - 6
src/MoonSharp.Interpreter/CoreLib/CoroutineModule.cs

@@ -14,7 +14,7 @@ namespace MoonSharp.Interpreter.CoreLib
 	[MoonSharpModule(Namespace = "coroutine")]
 	[MoonSharpModule(Namespace = "coroutine")]
 	public class CoroutineModule
 	public class CoroutineModule
 	{
 	{
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue create(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue create(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			if (args[0].Type != DataType.Function && args[0].Type != DataType.ClrFunction)
 			if (args[0].Type != DataType.Function && args[0].Type != DataType.ClrFunction)
@@ -23,7 +23,7 @@ namespace MoonSharp.Interpreter.CoreLib
 			return executionContext.GetScript().CreateCoroutine(args[0]);
 			return executionContext.GetScript().CreateCoroutine(args[0]);
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue wrap(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue wrap(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			if (args[0].Type != DataType.Function && args[0].Type != DataType.ClrFunction)
 			if (args[0].Type != DataType.Function && args[0].Type != DataType.ClrFunction)
@@ -41,7 +41,7 @@ namespace MoonSharp.Interpreter.CoreLib
 			return handle.Coroutine.Resume(args.GetArray());
 			return handle.Coroutine.Resume(args.GetArray());
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue resume(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue resume(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue handle = args.AsType(0, "resume", DataType.Thread);
 			DynValue handle = args.AsType(0, "resume", DataType.Thread);
@@ -84,7 +84,7 @@ namespace MoonSharp.Interpreter.CoreLib
 			}
 			}
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue yield(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue yield(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return DynValue.NewYieldReq(args.GetArray());
 			return DynValue.NewYieldReq(args.GetArray());
@@ -92,14 +92,14 @@ namespace MoonSharp.Interpreter.CoreLib
 
 
 
 
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue running(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue running(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			Coroutine C = executionContext.GetCallingCoroutine();
 			Coroutine C = executionContext.GetCallingCoroutine();
 			return DynValue.NewTuple(DynValue.NewCoroutine(C), DynValue.NewBoolean(C.State == CoroutineState.Main));
 			return DynValue.NewTuple(DynValue.NewCoroutine(C), DynValue.NewBoolean(C.State == CoroutineState.Main));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue status(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue status(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue handle = args.AsType(0, "status", DataType.Thread);
 			DynValue handle = args.AsType(0, "status", DataType.Thread);

+ 10 - 10
src/MoonSharp.Interpreter/CoreLib/DebugModule.cs

@@ -13,7 +13,7 @@ namespace MoonSharp.Interpreter.CoreLib
 	[MoonSharpModule(Namespace = "debug")]
 	[MoonSharpModule(Namespace = "debug")]
 	public class DebugModule
 	public class DebugModule
 	{
 	{
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue debug(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue debug(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			Script script = executionContext.GetScript();
 			Script script = executionContext.GetScript();
@@ -42,7 +42,7 @@ namespace MoonSharp.Interpreter.CoreLib
 			}
 			}
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue getuservalue(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue getuservalue(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue v = args[0];
 			DynValue v = args[0];
@@ -53,7 +53,7 @@ namespace MoonSharp.Interpreter.CoreLib
 			return v.UserData.UserValue ?? DynValue.Nil;
 			return v.UserData.UserValue ?? DynValue.Nil;
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue setuservalue(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue setuservalue(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue v = args.AsType(0, "setuservalue", DataType.UserData, false);
 			DynValue v = args.AsType(0, "setuservalue", DataType.UserData, false);
@@ -62,13 +62,13 @@ namespace MoonSharp.Interpreter.CoreLib
 			return v.UserData.UserValue = t;
 			return v.UserData.UserValue = t;
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue getregistry(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue getregistry(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return DynValue.NewTable(executionContext.GetScript().Registry);
 			return DynValue.NewTable(executionContext.GetScript().Registry);
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue getmetatable(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue getmetatable(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue v = args[0];
 			DynValue v = args[0];
@@ -82,7 +82,7 @@ namespace MoonSharp.Interpreter.CoreLib
 				return DynValue.Nil;
 				return DynValue.Nil;
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue setmetatable(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue setmetatable(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue v = args[0];
 			DynValue v = args[0];
@@ -100,7 +100,7 @@ namespace MoonSharp.Interpreter.CoreLib
 			return v;
 			return v;
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue getupvalue(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue getupvalue(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			var index = (int)args.AsType(1, "getupvalue", DataType.Number, false).Number - 1;
 			var index = (int)args.AsType(1, "getupvalue", DataType.Number, false).Number - 1;
@@ -121,7 +121,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		}
 		}
 
 
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue upvalueid(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue upvalueid(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			var index = (int)args.AsType(1, "getupvalue", DataType.Number, false).Number - 1;
 			var index = (int)args.AsType(1, "getupvalue", DataType.Number, false).Number - 1;
@@ -140,7 +140,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		}
 		}
 
 
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue setupvalue(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue setupvalue(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			var index = (int)args.AsType(1, "setupvalue", DataType.Number, false).Number - 1;
 			var index = (int)args.AsType(1, "setupvalue", DataType.Number, false).Number - 1;
@@ -161,7 +161,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		}
 		}
 
 
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue traceback(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue traceback(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			StringBuilder sb = new StringBuilder();
 			StringBuilder sb = new StringBuilder();

+ 2 - 2
src/MoonSharp.Interpreter/CoreLib/DynamicModule.cs

@@ -22,7 +22,7 @@ namespace MoonSharp.Interpreter.CoreLib
 			UserData.RegisterType<DynamicExprWrapper>(InteropAccessMode.HideMembers);
 			UserData.RegisterType<DynamicExprWrapper>(InteropAccessMode.HideMembers);
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue eval(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue eval(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			try
 			try
@@ -52,7 +52,7 @@ namespace MoonSharp.Interpreter.CoreLib
 			}
 			}
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue prepare(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue prepare(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			try
 			try

+ 2 - 2
src/MoonSharp.Interpreter/CoreLib/ErrorHandlingModule.cs

@@ -13,7 +13,7 @@ namespace MoonSharp.Interpreter.CoreLib
 	[MoonSharpModule]
 	[MoonSharpModule]
 	public class ErrorHandlingModule
 	public class ErrorHandlingModule
 	{
 	{
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue pcall(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue pcall(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return SetErrorHandlerStrategy("pcall", executionContext, args, null);
 			return SetErrorHandlerStrategy("pcall", executionContext, args, null);
@@ -106,7 +106,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		}
 		}
 
 
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue xpcall(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue xpcall(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			List<DynValue> a = new List<DynValue>();
 			List<DynValue> a = new List<DynValue>();

+ 10 - 10
src/MoonSharp.Interpreter/CoreLib/IoModule.cs

@@ -103,14 +103,14 @@ namespace MoonSharp.Interpreter.CoreLib
 		}
 		}
 
 
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue close(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue close(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			FileUserDataBase outp = args.AsUserData<FileUserDataBase>(0, "close", true) ?? GetDefaultFile(executionContext, StandardFileType.StdOut);
 			FileUserDataBase outp = args.AsUserData<FileUserDataBase>(0, "close", true) ?? GetDefaultFile(executionContext, StandardFileType.StdOut);
 			return outp.close(executionContext, args);
 			return outp.close(executionContext, args);
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue flush(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue flush(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			FileUserDataBase outp = args.AsUserData<FileUserDataBase>(0, "close", true) ?? GetDefaultFile(executionContext, StandardFileType.StdOut);
 			FileUserDataBase outp = args.AsUserData<FileUserDataBase>(0, "close", true) ?? GetDefaultFile(executionContext, StandardFileType.StdOut);
@@ -119,13 +119,13 @@ namespace MoonSharp.Interpreter.CoreLib
 		}
 		}
 
 
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue input(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue input(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return HandleDefaultStreamSetter(executionContext, args, StandardFileType.StdIn);
 			return HandleDefaultStreamSetter(executionContext, args, StandardFileType.StdIn);
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue output(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue output(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return HandleDefaultStreamSetter(executionContext, args, StandardFileType.StdOut);
 			return HandleDefaultStreamSetter(executionContext, args, StandardFileType.StdOut);
@@ -161,7 +161,7 @@ namespace MoonSharp.Interpreter.CoreLib
 			return new System.Text.UTF8Encoding(false); 
 			return new System.Text.UTF8Encoding(false); 
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue lines(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue lines(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			string filename = args.AsType(0, "lines", DataType.String, false).String;
 			string filename = args.AsType(0, "lines", DataType.String, false).String;
@@ -192,7 +192,7 @@ namespace MoonSharp.Interpreter.CoreLib
 			}
 			}
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue open(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue open(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			string filename = args.AsType(0, "open", DataType.String, false).String;
 			string filename = args.AsType(0, "open", DataType.String, false).String;
@@ -257,7 +257,7 @@ namespace MoonSharp.Interpreter.CoreLib
 				return ex.Message;
 				return ex.Message;
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue type(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue type(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			if (args[0].Type != DataType.UserData)
 			if (args[0].Type != DataType.UserData)
@@ -273,21 +273,21 @@ namespace MoonSharp.Interpreter.CoreLib
 				return DynValue.NewString("closed file");
 				return DynValue.NewString("closed file");
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue read(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue read(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			FileUserDataBase file = GetDefaultFile(executionContext, StandardFileType.StdIn);
 			FileUserDataBase file = GetDefaultFile(executionContext, StandardFileType.StdIn);
 			return file.read(executionContext, args);
 			return file.read(executionContext, args);
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue write(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue write(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			FileUserDataBase file = GetDefaultFile(executionContext, StandardFileType.StdOut);
 			FileUserDataBase file = GetDefaultFile(executionContext, StandardFileType.StdOut);
 			return file.write(executionContext, args);
 			return file.write(executionContext, args);
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue tmpfile(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue tmpfile(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			string tmpfilename = Script.GlobalOptions.Platform.IO_OS_GetTempFilename();
 			string tmpfilename = Script.GlobalOptions.Platform.IO_OS_GetTempFilename();

+ 7 - 7
src/MoonSharp.Interpreter/CoreLib/LoadModule.cs

@@ -51,7 +51,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		// or to "=(load)" otherwise.
 		// or to "=(load)" otherwise.
 		// 
 		// 
 		// The string mode is ignored, and assumed to be "t"; 
 		// The string mode is ignored, and assumed to be "t"; 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue load(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue load(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return load_impl(executionContext, args, null);
 			return load_impl(executionContext, args, null);
@@ -61,7 +61,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		// ----------------------------------------------------------------
 		// ----------------------------------------------------------------
 		// Same as load, except that "env" defaults to the current environment of the function
 		// Same as load, except that "env" defaults to the current environment of the function
 		// calling load, instead of the actual global environment.
 		// calling load, instead of the actual global environment.
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue loadsafe(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue loadsafe(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return load_impl(executionContext, args, GetSafeDefaultEnv(executionContext));
 			return load_impl(executionContext, args, GetSafeDefaultEnv(executionContext));
@@ -116,7 +116,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		// ----------------------------------------------------------------
 		// ----------------------------------------------------------------
 		// Similar to load, but gets the chunk from file filename or from the standard input, 
 		// Similar to load, but gets the chunk from file filename or from the standard input, 
 		// if no file name is given. INCOMPAT: stdin not supported, mode ignored
 		// if no file name is given. INCOMPAT: stdin not supported, mode ignored
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue loadfile(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue loadfile(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return loadfile_impl(executionContext, args, null);
 			return loadfile_impl(executionContext, args, null);
@@ -126,7 +126,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		// ----------------------------------------------------------------
 		// ----------------------------------------------------------------
 		// Same as loadfile, except that "env" defaults to the current environment of the function
 		// Same as loadfile, except that "env" defaults to the current environment of the function
 		// calling load, instead of the actual global environment.
 		// calling load, instead of the actual global environment.
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue loadfilesafe(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue loadfilesafe(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return loadfile_impl(executionContext, args, GetSafeDefaultEnv(executionContext));
 			return loadfile_impl(executionContext, args, GetSafeDefaultEnv(executionContext));
@@ -168,7 +168,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		//Opens the named file and executes its contents as a Lua chunk. When called without arguments, 
 		//Opens the named file and executes its contents as a Lua chunk. When called without arguments, 
 		//dofile executes the contents of the standard input (stdin). Returns all values returned by the chunk. 
 		//dofile executes the contents of the standard input (stdin). Returns all values returned by the chunk. 
 		//In case of errors, dofile propagates the error to its caller (that is, dofile does not run in protected mode). 
 		//In case of errors, dofile propagates the error to its caller (that is, dofile does not run in protected mode). 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue dofile(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue dofile(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			try
 			try
@@ -207,7 +207,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		//
 		//
 		//If there is any error loading or running the module, or if it cannot find any loader for the module, then require 
 		//If there is any error loading or running the module, or if it cannot find any loader for the module, then require 
 		//signals an error. 
 		//signals an error. 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue __require_clr_impl(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue __require_clr_impl(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			Script S = executionContext.GetScript();
 			Script S = executionContext.GetScript();
@@ -219,7 +219,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		}
 		}
 
 
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public const string require = @"
 		public const string require = @"
 function(modulename)
 function(modulename)
 	if (package == nil) then package = { }; end
 	if (package == nil) then package = { }; end

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

@@ -13,9 +13,9 @@ namespace MoonSharp.Interpreter.CoreLib
 	[MoonSharpModule(Namespace = "math")]
 	[MoonSharpModule(Namespace = "math")]
 	public class MathModule
 	public class MathModule
 	{
 	{
-		[MoonSharpConstant]
+		[MoonSharpModuleConstant]
 		public const double pi = Math.PI;
 		public const double pi = Math.PI;
-		[MoonSharpConstant]
+		[MoonSharpModuleConstant]
 		public const double huge = double.MaxValue;
 		public const double huge = double.MaxValue;
 
 
 		private static Random GetRandom(Script s)
 		private static Random GetRandom(Script s)
@@ -80,79 +80,79 @@ namespace MoonSharp.Interpreter.CoreLib
 		}
 		}
 
 
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue abs(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue abs(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return exec1(args, "abs", d => Math.Abs(d));
 			return exec1(args, "abs", d => Math.Abs(d));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue acos(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue acos(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return exec1(args, "acos", d => Math.Acos(d));
 			return exec1(args, "acos", d => Math.Acos(d));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue asin(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue asin(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return exec1(args, "asin", d => Math.Asin(d));
 			return exec1(args, "asin", d => Math.Asin(d));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue atan(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue atan(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return exec1(args, "atan", d => Math.Atan(d));
 			return exec1(args, "atan", d => Math.Atan(d));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue atan2(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue atan2(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return exec2(args, "atan2", (d1, d2) => Math.Atan2(d1, d2));
 			return exec2(args, "atan2", (d1, d2) => Math.Atan2(d1, d2));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue ceil(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue ceil(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return exec1(args, "ceil", d => Math.Ceiling(d));
 			return exec1(args, "ceil", d => Math.Ceiling(d));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue cos(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue cos(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return exec1(args, "cos", d => Math.Cos(d));
 			return exec1(args, "cos", d => Math.Cos(d));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue cosh(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue cosh(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return exec1(args, "cosh", d => Math.Cosh(d));
 			return exec1(args, "cosh", d => Math.Cosh(d));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue deg(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue deg(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return exec1(args, "deg", d => d * 180.0 / Math.PI);
 			return exec1(args, "deg", d => d * 180.0 / Math.PI);
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue exp(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue exp(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return exec1(args, "exp", d => Math.Exp(d));
 			return exec1(args, "exp", d => Math.Exp(d));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue floor(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue floor(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return exec1(args, "floor", d => Math.Floor(d));
 			return exec1(args, "floor", d => Math.Floor(d));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue fmod(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue fmod(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return exec2(args, "fmod", (d1, d2) => Math.IEEERemainder(d1, d2));
 			return exec2(args, "fmod", (d1, d2) => Math.IEEERemainder(d1, d2));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue frexp(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue frexp(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			// http://stackoverflow.com/questions/389993/extracting-mantissa-and-exponent-from-double-in-c-sharp
 			// http://stackoverflow.com/questions/389993/extracting-mantissa-and-exponent-from-double-in-c-sharp
@@ -211,31 +211,31 @@ namespace MoonSharp.Interpreter.CoreLib
 			return DynValue.NewTuple(DynValue.NewNumber(m), DynValue.NewNumber(e));
 			return DynValue.NewTuple(DynValue.NewNumber(m), DynValue.NewNumber(e));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue ldexp(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue ldexp(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return exec2(args, "ldexp", (d1, d2) => d1 * Math.Pow(2, d2));
 			return exec2(args, "ldexp", (d1, d2) => d1 * Math.Pow(2, d2));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue log(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue log(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return exec2n(args, "log", Math.E, (d1, d2) => Math.Log(d1, d2));
 			return exec2n(args, "log", Math.E, (d1, d2) => Math.Log(d1, d2));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue max(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue max(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return execaccum(args, "max", (d1, d2) => Math.Max(d1, d2));
 			return execaccum(args, "max", (d1, d2) => Math.Max(d1, d2));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue min(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue min(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return execaccum(args, "min", (d1, d2) => Math.Min(d1, d2));
 			return execaccum(args, "min", (d1, d2) => Math.Min(d1, d2));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue modf(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue modf(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue arg = args.AsType(0, "modf", DataType.Number, false);
 			DynValue arg = args.AsType(0, "modf", DataType.Number, false);
@@ -243,19 +243,19 @@ namespace MoonSharp.Interpreter.CoreLib
 		}
 		}
 
 
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue pow(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue pow(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return exec2(args, "pow", (d1, d2) => Math.Pow(d1, d2));
 			return exec2(args, "pow", (d1, d2) => Math.Pow(d1, d2));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue rad(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue rad(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return exec1(args, "rad", d => d * Math.PI / 180.0);
 			return exec1(args, "rad", d => d * Math.PI / 180.0);
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue random(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue random(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue m = args.AsType(0, "random", DataType.Number, true);
 			DynValue m = args.AsType(0, "random", DataType.Number, true);
@@ -281,7 +281,7 @@ namespace MoonSharp.Interpreter.CoreLib
 			return DynValue.NewNumber(d);
 			return DynValue.NewNumber(d);
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue randomseed(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue randomseed(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue arg = args.AsType(0, "randomseed", DataType.Number, false);
 			DynValue arg = args.AsType(0, "randomseed", DataType.Number, false);
@@ -290,31 +290,31 @@ namespace MoonSharp.Interpreter.CoreLib
 			return DynValue.Nil;
 			return DynValue.Nil;
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue sin(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue sin(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return exec1(args, "sin", d => Math.Sin(d));
 			return exec1(args, "sin", d => Math.Sin(d));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue sinh(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue sinh(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return exec1(args, "sinh", d => Math.Sinh(d));
 			return exec1(args, "sinh", d => Math.Sinh(d));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue sqrt(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue sqrt(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return exec1(args, "sqrt", d => Math.Sqrt(d));
 			return exec1(args, "sqrt", d => Math.Sqrt(d));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue tan(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue tan(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return exec1(args, "tan", d => Math.Tan(d));
 			return exec1(args, "tan", d => Math.Tan(d));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue tanh(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue tanh(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return exec1(args, "tanh", d => Math.Tanh(d));
 			return exec1(args, "tanh", d => Math.Tanh(d));

+ 6 - 6
src/MoonSharp.Interpreter/CoreLib/MetaTableModule.cs

@@ -18,7 +18,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		// types from Lua, only from C.) If metatable is nil, removes the metatable of the given table. 
 		// types from Lua, only from C.) If metatable is nil, removes the metatable of the given table. 
 		// If the original metatable has a "__metatable" field, raises an error ("cannot change a protected metatable").
 		// If the original metatable has a "__metatable" field, raises an error ("cannot change a protected metatable").
 		// This function returns table. 
 		// This function returns table. 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue setmetatable(ScriptExecutionContext executionContext, CallbackArguments args)  
 		public static DynValue setmetatable(ScriptExecutionContext executionContext, CallbackArguments args)  
 		{
 		{
 			DynValue table = args.AsType(0, "setmetatable", DataType.Table);
 			DynValue table = args.AsType(0, "setmetatable", DataType.Table);
@@ -39,7 +39,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		// -------------------------------------------------------------------------------------------------------------------
 		// -------------------------------------------------------------------------------------------------------------------
 		// If object does not have a metatable, returns nil. Otherwise, if the object's metatable 
 		// If object does not have a metatable, returns nil. Otherwise, if the object's metatable 
 		// has a "__metatable" field, returns the associated value. Otherwise, returns the metatable of the given object. 
 		// has a "__metatable" field, returns the associated value. Otherwise, returns the metatable of the given object. 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue getmetatable(ScriptExecutionContext executionContext, CallbackArguments args)  
 		public static DynValue getmetatable(ScriptExecutionContext executionContext, CallbackArguments args)  
 		{
 		{
 			DynValue obj = args[0];
 			DynValue obj = args[0];
@@ -67,7 +67,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		// rawget (table, index)
 		// rawget (table, index)
 		// -------------------------------------------------------------------------------------------------------------------
 		// -------------------------------------------------------------------------------------------------------------------
 		// Gets the real value of table[index], without invoking any metamethod. table must be a table; index may be any value.
 		// Gets the real value of table[index], without invoking any metamethod. table must be a table; index may be any value.
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue rawget(ScriptExecutionContext executionContext, CallbackArguments args)  
 		public static DynValue rawget(ScriptExecutionContext executionContext, CallbackArguments args)  
 		{
 		{
 			DynValue table = args.AsType(0, "rawget", DataType.Table);
 			DynValue table = args.AsType(0, "rawget", DataType.Table);
@@ -81,7 +81,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		// Sets the real value of table[index] to value, without invoking any metamethod. table must be a table, 
 		// Sets the real value of table[index] to value, without invoking any metamethod. table must be a table, 
 		// index any value different from nil and NaN, and value any Lua value.
 		// index any value different from nil and NaN, and value any Lua value.
 		// This function returns table. 
 		// This function returns table. 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue rawset(ScriptExecutionContext executionContext, CallbackArguments args)  
 		public static DynValue rawset(ScriptExecutionContext executionContext, CallbackArguments args)  
 		{
 		{
 			DynValue table = args.AsType(0, "rawset", DataType.Table);
 			DynValue table = args.AsType(0, "rawset", DataType.Table);
@@ -95,7 +95,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		// rawequal (v1, v2)
 		// rawequal (v1, v2)
 		// -------------------------------------------------------------------------------------------------------------------
 		// -------------------------------------------------------------------------------------------------------------------
 		// Checks whether v1 is equal to v2, without invoking any metamethod. Returns a boolean. 
 		// Checks whether v1 is equal to v2, without invoking any metamethod. Returns a boolean. 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue rawequal(ScriptExecutionContext executionContext, CallbackArguments args)  
 		public static DynValue rawequal(ScriptExecutionContext executionContext, CallbackArguments args)  
 		{
 		{
 			DynValue v1 = args[0];
 			DynValue v1 = args[0];
@@ -107,7 +107,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		//rawlen (v)
 		//rawlen (v)
 		// -------------------------------------------------------------------------------------------------------------------
 		// -------------------------------------------------------------------------------------------------------------------
 		//Returns the length of the object v, which must be a table or a string, without invoking any metamethod. Returns an integer number.	
 		//Returns the length of the object v, which must be a table or a string, without invoking any metamethod. Returns an integer number.	
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue rawlen(ScriptExecutionContext executionContext, CallbackArguments args) 
 		public static DynValue rawlen(ScriptExecutionContext executionContext, CallbackArguments args) 
 		{
 		{
 			if (args[0].Type != DataType.String && args[0].Type != DataType.Table)
 			if (args[0].Type != DataType.String && args[0].Type != DataType.Table)

+ 7 - 7
src/MoonSharp.Interpreter/CoreLib/OsSystemModule.cs

@@ -15,7 +15,7 @@ namespace MoonSharp.Interpreter.CoreLib
 	[MoonSharpModule(Namespace = "os")]
 	[MoonSharpModule(Namespace = "os")]
 	public class OsSystemModule
 	public class OsSystemModule
 	{
 	{
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue execute(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue execute(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue v = args.AsType(0, "execute", DataType.String, true);
 			DynValue v = args.AsType(0, "execute", DataType.String, true);
@@ -43,7 +43,7 @@ namespace MoonSharp.Interpreter.CoreLib
 			}
 			}
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue exit(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue exit(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue v_exitCode = args.AsType(0, "exit", DataType.Number, true);
 			DynValue v_exitCode = args.AsType(0, "exit", DataType.Number, true);
@@ -57,7 +57,7 @@ namespace MoonSharp.Interpreter.CoreLib
 			throw new InvalidOperationException("Unreachable code.. reached.");
 			throw new InvalidOperationException("Unreachable code.. reached.");
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue getenv(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue getenv(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue varName = args.AsType(0, "getenv", DataType.String, false);
 			DynValue varName = args.AsType(0, "getenv", DataType.String, false);
@@ -70,7 +70,7 @@ namespace MoonSharp.Interpreter.CoreLib
 				return DynValue.NewString(val);
 				return DynValue.NewString(val);
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue remove(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue remove(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			string fileName = args.AsType(0, "remove", DataType.String, false).String;
 			string fileName = args.AsType(0, "remove", DataType.String, false).String;
@@ -96,7 +96,7 @@ namespace MoonSharp.Interpreter.CoreLib
 			}
 			}
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue rename(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue rename(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			string fileNameOld = args.AsType(0, "rename", DataType.String, false).String;
 			string fileNameOld = args.AsType(0, "rename", DataType.String, false).String;
@@ -120,13 +120,13 @@ namespace MoonSharp.Interpreter.CoreLib
 			}
 			}
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue setlocale(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue setlocale(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return DynValue.NewString("n/a");
 			return DynValue.NewString("n/a");
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue tmpname(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue tmpname(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return DynValue.NewString(Script.GlobalOptions.Platform.IO_OS_GetTempFilename());
 			return DynValue.NewString(Script.GlobalOptions.Platform.IO_OS_GetTempFilename());

+ 4 - 4
src/MoonSharp.Interpreter/CoreLib/OsTimeModule.cs

@@ -31,13 +31,13 @@ namespace MoonSharp.Interpreter.CoreLib
 			return Epoch + ts;
 			return Epoch + ts;
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue clock(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue clock(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return GetUnixTime(DateTime.UtcNow, Time0);
 			return GetUnixTime(DateTime.UtcNow, Time0);
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue difftime(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue difftime(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue t2 = args.AsType(0, "difftime", DataType.Number, false);
 			DynValue t2 = args.AsType(0, "difftime", DataType.Number, false);
@@ -49,7 +49,7 @@ namespace MoonSharp.Interpreter.CoreLib
 			return DynValue.NewNumber(t2.Number - t1.Number);
 			return DynValue.NewNumber(t2.Number - t1.Number);
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue time(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue time(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DateTime date = DateTime.UtcNow;
 			DateTime date = DateTime.UtcNow;
@@ -97,7 +97,7 @@ namespace MoonSharp.Interpreter.CoreLib
 			return null;
 			return null;
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue date(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue date(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DateTime reference = DateTime.UtcNow;
 			DateTime reference = DateTime.UtcNow;

+ 1 - 1
src/MoonSharp.Interpreter/CoreLib/StringLib/KopiLua_StrLib.cs

@@ -59,7 +59,7 @@ using MoonSharp.Interpreter.Execution;
 
 
 namespace MoonSharp.Interpreter.CoreLib.StringLib
 namespace MoonSharp.Interpreter.CoreLib.StringLib
 {
 {
-	public class KopiLua_StringLib : LuaBase
+	internal class KopiLua_StringLib : LuaBase
 	{
 	{
 		public const int LUA_MAXCAPTURES = 32;
 		public const int LUA_MAXCAPTURES = 32;
 
 

+ 15 - 15
src/MoonSharp.Interpreter/CoreLib/StringModule.cs

@@ -24,7 +24,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		}
 		}
 
 
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue dump(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue dump(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue fn = args.AsType(0, "dump", DataType.Function, false);
 			DynValue fn = args.AsType(0, "dump", DataType.Function, false);
@@ -48,7 +48,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		}
 		}
 
 
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue @char(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue @char(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			StringBuilder sb = new StringBuilder(args.Count);
 			StringBuilder sb = new StringBuilder(args.Count);
@@ -79,7 +79,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		}
 		}
 
 
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue @byte(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue @byte(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue vs = args.AsType(0, "byte", DataType.String, false);
 			DynValue vs = args.AsType(0, "byte", DataType.String, false);
@@ -90,7 +90,7 @@ namespace MoonSharp.Interpreter.CoreLib
 				i => Unicode2Ascii(i));
 				i => Unicode2Ascii(i));
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue unicode(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue unicode(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue vs = args.AsType(0, "unicode", DataType.String, false);
 			DynValue vs = args.AsType(0, "unicode", DataType.String, false);
@@ -141,7 +141,7 @@ namespace MoonSharp.Interpreter.CoreLib
 			return s.Length - i;
 			return s.Length - i;
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue len(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue len(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue vs = args.AsType(0, "len", DataType.String, false);
 			DynValue vs = args.AsType(0, "len", DataType.String, false);
@@ -150,26 +150,26 @@ namespace MoonSharp.Interpreter.CoreLib
 
 
 
 
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue match(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue match(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return executionContext.EmulateClassicCall(args, "match", KopiLua_StringLib.str_match);
 			return executionContext.EmulateClassicCall(args, "match", KopiLua_StringLib.str_match);
 		}
 		}
 
 
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue gmatch(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue gmatch(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return executionContext.EmulateClassicCall(args, "gmatch", KopiLua_StringLib.str_gmatch);
 			return executionContext.EmulateClassicCall(args, "gmatch", KopiLua_StringLib.str_gmatch);
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue gsub(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue gsub(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return executionContext.EmulateClassicCall(args, "gsub", KopiLua_StringLib.str_gsub);
 			return executionContext.EmulateClassicCall(args, "gsub", KopiLua_StringLib.str_gsub);
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue find(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue find(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return executionContext.EmulateClassicCall(args, "find",
 			return executionContext.EmulateClassicCall(args, "find",
@@ -177,21 +177,21 @@ namespace MoonSharp.Interpreter.CoreLib
 		}
 		}
 
 
 
 
-        [MoonSharpMethod]
+        [MoonSharpModuleMethod]
         public static DynValue lower(ScriptExecutionContext executionContext, CallbackArguments args)
         public static DynValue lower(ScriptExecutionContext executionContext, CallbackArguments args)
         {
         {
             DynValue arg_s = args.AsType(0, "lower", DataType.String, false);
             DynValue arg_s = args.AsType(0, "lower", DataType.String, false);
             return DynValue.NewString(arg_s.String.ToLower());
             return DynValue.NewString(arg_s.String.ToLower());
         }
         }
 
 
-        [MoonSharpMethod]
+        [MoonSharpModuleMethod]
         public static DynValue upper(ScriptExecutionContext executionContext, CallbackArguments args)
         public static DynValue upper(ScriptExecutionContext executionContext, CallbackArguments args)
         {
         {
             DynValue arg_s = args.AsType(0, "upper", DataType.String, false);
             DynValue arg_s = args.AsType(0, "upper", DataType.String, false);
             return DynValue.NewString(arg_s.String.ToUpper());
             return DynValue.NewString(arg_s.String.ToUpper());
         }
         }
 
 
-        [MoonSharpMethod]
+        [MoonSharpModuleMethod]
         public static DynValue rep(ScriptExecutionContext executionContext, CallbackArguments args)
         public static DynValue rep(ScriptExecutionContext executionContext, CallbackArguments args)
         {
         {
             DynValue arg_s = args.AsType(0, "rep", DataType.String, false);
             DynValue arg_s = args.AsType(0, "rep", DataType.String, false);
@@ -219,7 +219,7 @@ namespace MoonSharp.Interpreter.CoreLib
             return DynValue.NewString(result.ToString());
             return DynValue.NewString(result.ToString());
         }
         }
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue format(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue format(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return executionContext.EmulateClassicCall(args, "format", KopiLua_StringLib.str_format);
 			return executionContext.EmulateClassicCall(args, "format", KopiLua_StringLib.str_format);
@@ -227,7 +227,7 @@ namespace MoonSharp.Interpreter.CoreLib
 
 
 
 
 
 
-        [MoonSharpMethod]
+        [MoonSharpModuleMethod]
         public static DynValue reverse(ScriptExecutionContext executionContext, CallbackArguments args)
         public static DynValue reverse(ScriptExecutionContext executionContext, CallbackArguments args)
         {
         {
             DynValue arg_s = args.AsType(0, "reverse", DataType.String, false);
             DynValue arg_s = args.AsType(0, "reverse", DataType.String, false);
@@ -243,7 +243,7 @@ namespace MoonSharp.Interpreter.CoreLib
             return DynValue.NewString(new String(elements));
             return DynValue.NewString(new String(elements));
         }
         }
 
 
-        [MoonSharpMethod]
+        [MoonSharpModuleMethod]
         public static DynValue sub(ScriptExecutionContext executionContext, CallbackArguments args)
         public static DynValue sub(ScriptExecutionContext executionContext, CallbackArguments args)
         {
         {
             DynValue arg_s = args.AsType(0, "sub", DataType.String, false);
             DynValue arg_s = args.AsType(0, "sub", DataType.String, false);

+ 3 - 3
src/MoonSharp.Interpreter/CoreLib/TableIteratorsModule.cs

@@ -18,7 +18,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		// Otherwise, returns three values: an iterator function, the table t, and 0, so that the construction
 		// Otherwise, returns three values: an iterator function, the table t, and 0, so that the construction
 		//	  for i,v in ipairs(t) do body end
 		//	  for i,v in ipairs(t) do body end
 		// will iterate over the pairs (1,t[1]), (2,t[2]), ..., up to the first integer key absent from the table. 
 		// will iterate over the pairs (1,t[1]), (2,t[2]), ..., up to the first integer key absent from the table. 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue ipairs(ScriptExecutionContext executionContext, CallbackArguments args) 
 		public static DynValue ipairs(ScriptExecutionContext executionContext, CallbackArguments args) 
 		{
 		{
 			DynValue table = args[0];
 			DynValue table = args[0];
@@ -35,7 +35,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		//     for k,v in pairs(t) do body end
 		//     for k,v in pairs(t) do body end
 		// will iterate over all key–value pairs of table t.
 		// will iterate over all key–value pairs of table t.
 		// See function next for the caveats of modifying the table during its traversal. 
 		// See function next for the caveats of modifying the table during its traversal. 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue pairs(ScriptExecutionContext executionContext, CallbackArguments args) 
 		public static DynValue pairs(ScriptExecutionContext executionContext, CallbackArguments args) 
 		{
 		{
 			DynValue table = args[0];
 			DynValue table = args[0];
@@ -56,7 +56,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		// (To traverse a table in numeric order, use a numerical for.)
 		// (To traverse a table in numeric order, use a numerical for.)
 		// The behavior of next is undefined if, during the traversal, you assign any value to a non-existent field in the table. 
 		// The behavior of next is undefined if, during the traversal, you assign any value to a non-existent field in the table. 
 		// You may however modify existing fields. In particular, you may clear existing fields. 
 		// You may however modify existing fields. In particular, you may clear existing fields. 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue next(ScriptExecutionContext executionContext, CallbackArguments args) 
 		public static DynValue next(ScriptExecutionContext executionContext, CallbackArguments args) 
 		{
 		{
 			DynValue table = args.AsType(0, "next", DataType.Table);
 			DynValue table = args.AsType(0, "next", DataType.Table);

+ 11 - 8
src/MoonSharp.Interpreter/CoreLib/TableModule.cs

@@ -13,7 +13,7 @@ namespace MoonSharp.Interpreter.CoreLib
 	[MoonSharpModule(Namespace = "table")]
 	[MoonSharpModule(Namespace = "table")]
 	public class TableModule
 	public class TableModule
 	{
 	{
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue unpack(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue unpack(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue s = args.AsType(0, "unpack", DataType.Table, false);
 			DynValue s = args.AsType(0, "unpack", DataType.Table, false);
@@ -34,7 +34,7 @@ namespace MoonSharp.Interpreter.CoreLib
 			return DynValue.NewTuple(v);
 			return DynValue.NewTuple(v);
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue pack(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue pack(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			Table t = new Table(executionContext.GetScript());
 			Table t = new Table(executionContext.GetScript());
@@ -48,7 +48,7 @@ namespace MoonSharp.Interpreter.CoreLib
 			return v;
 			return v;
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue sort(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue sort(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue vlist = args.AsType(0, "sort", DataType.Table, false);
 			DynValue vlist = args.AsType(0, "sort", DataType.Table, false);
@@ -128,7 +128,7 @@ namespace MoonSharp.Interpreter.CoreLib
 			return 0;
 			return 0;
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue insert(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue insert(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue vlist = args.AsType(0, "table.insert", DataType.Table, false);
 			DynValue vlist = args.AsType(0, "table.insert", DataType.Table, false);
@@ -166,7 +166,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		}
 		}
 
 
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue remove(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue remove(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue vlist = args.AsType(0, "table.remove", DataType.Table, false);
 			DynValue vlist = args.AsType(0, "table.remove", DataType.Table, false);
@@ -200,7 +200,7 @@ namespace MoonSharp.Interpreter.CoreLib
 		//Given a list where all elements are strings or numbers, returns the string list[i]..sep..list[i+1] (...) sep..list[j]. 
 		//Given a list where all elements are strings or numbers, returns the string list[i]..sep..list[i+1] (...) sep..list[j]. 
 		//The default value for sep is the empty string, the default for i is 1, and the default for j is #list. If i is greater 
 		//The default value for sep is the empty string, the default for i is 1, and the default for j is #list. If i is greater 
 		//than j, returns the empty string. 
 		//than j, returns the empty string. 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue concat(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue concat(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			DynValue vlist = args.AsType(0, "concat", DataType.Table, false);
 			DynValue vlist = args.AsType(0, "concat", DataType.Table, false);
@@ -269,16 +269,19 @@ namespace MoonSharp.Interpreter.CoreLib
 	}
 	}
 
 
 
 
+	/// <summary>
+	/// Class exposing table.unpack and table.pack in the global namespace (to work around the most common Lua 5.1 compatibility issue).
+	/// </summary>
 	[MoonSharpModule]
 	[MoonSharpModule]
 	public class TableModule_Globals
 	public class TableModule_Globals
 	{
 	{
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue unpack(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue unpack(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return TableModule.unpack(executionContext, args);
 			return TableModule.unpack(executionContext, args);
 		}
 		}
 
 
-		[MoonSharpMethod]
+		[MoonSharpModuleMethod]
 		public static DynValue pack(ScriptExecutionContext executionContext, CallbackArguments args)
 		public static DynValue pack(ScriptExecutionContext executionContext, CallbackArguments args)
 		{
 		{
 			return TableModule.pack(executionContext, args);
 			return TableModule.pack(executionContext, args);

+ 67 - 4
src/MoonSharp.Interpreter/DataTypes/Closure.cs

@@ -13,14 +13,30 @@ namespace MoonSharp.Interpreter
 	public class Closure : RefIdObject, IScriptPrivateResource
 	public class Closure : RefIdObject, IScriptPrivateResource
 	{
 	{
 		/// <summary>
 		/// <summary>
-		/// Gets the entry point location in bytecode .
+		/// Type of closure based on upvalues
 		/// </summary>
 		/// </summary>
-		public int EntryPointByteCodeLocation { get; private set; }
+		public enum UpvaluesType
+		{
+			/// <summary>
+			/// The closure has no upvalues (thus, technically, it's a function and not a closure!)
+			/// </summary>
+			None,
+			/// <summary>
+			/// The closure has _ENV as its only upvalue
+			/// </summary>
+			Environment,
+			/// <summary>
+			/// The closure is a "real" closure, with multiple upvalues
+			/// </summary>
+			Closure
+		}
+
 
 
 		/// <summary>
 		/// <summary>
-		/// Gets the ClosureContext for upvalues of this function
+		/// Gets the entry point location in bytecode .
 		/// </summary>
 		/// </summary>
-		public ClosureContext ClosureContext { get; private set; }
+		public int EntryPointByteCodeLocation { get; private set; }
+
 
 
 		/// <summary>
 		/// <summary>
 		/// Gets the script owning this function
 		/// Gets the script owning this function
@@ -33,6 +49,11 @@ namespace MoonSharp.Interpreter
 		/// </summary>
 		/// </summary>
 		private static ClosureContext emptyClosure = new ClosureContext();
 		private static ClosureContext emptyClosure = new ClosureContext();
 
 
+		/// <summary>
+		/// The current closure context
+		/// </summary>
+		internal ClosureContext ClosureContext { get; private set; }
+
 
 
 		/// <summary>
 		/// <summary>
 		/// Initializes a new instance of the <see cref="Closure"/> class.
 		/// Initializes a new instance of the <see cref="Closure"/> class.
@@ -105,8 +126,50 @@ namespace MoonSharp.Interpreter
 			return args => this.Call(args).ToObject<T>();
 			return args => this.Call(args).ToObject<T>();
 		}
 		}
 
 
+		/// <summary>
+		/// Gets the number of upvalues in this closure
+		/// </summary>
+		/// <returns>The number of upvalues in this closure</returns>
+		public int GetUpvaluesCount()
+		{
+			return ClosureContext.Count;
+		}
 
 
+		/// <summary>
+		/// Gets the name of the specified upvalue.
+		/// </summary>
+		/// <param name="idx">The index of the upvalue.</param>
+		/// <returns>The upvalue name</returns>
+		public string GetUpvalueName(int idx)
+		{
+			return ClosureContext.Symbols[idx];
+		}
+
+		/// <summary>
+		/// Gets the value of an upvalue 
+		/// </summary>
+		/// <param name="idx">The index of the upvalue.</param>
+		/// <returns>The value of an upvalue </returns>
+		public DynValue GetUpvalue(int idx)
+		{
+			return ClosureContext[idx];
+		}
 
 
+		/// <summary>
+		/// Gets the type of the upvalues contained in this closure
+		/// </summary>
+		/// <returns></returns>
+		public UpvaluesType GetUpvaluesType()
+		{
+			int count = GetUpvaluesCount();
+
+			if (count == 0)
+				return UpvaluesType.None;
+			else if (count == 1 && GetUpvalueName(0) == WellKnownSymbols.ENV)
+				return UpvaluesType.Environment;
+			else
+				return UpvaluesType.Closure;
+		}
 
 
 
 
 	}
 	}

+ 72 - 0
src/MoonSharp.Interpreter/Debugging/DebuggerAction.cs

@@ -5,40 +5,112 @@ using System.Text;
 
 
 namespace MoonSharp.Interpreter.Debugging
 namespace MoonSharp.Interpreter.Debugging
 {
 {
+	/// <summary>
+	/// Wrapper for a debugger initiated action 
+	/// </summary>
 	public class DebuggerAction
 	public class DebuggerAction
 	{
 	{
+		/// <summary>
+		/// Type of the action
+		/// </summary>
 		public enum ActionType
 		public enum ActionType
 		{
 		{
+			/// <summary>
+			/// Step-in at the bytecode level
+			/// </summary>
 			ByteCodeStepIn,
 			ByteCodeStepIn,
+			/// <summary>
+			/// Step-over at the bytecode level
+			/// </summary>
 			ByteCodeStepOver,
 			ByteCodeStepOver,
+			/// <summary>
+			/// Step-out at the bytecode level
+			/// </summary>
 			ByteCodeStepOut,
 			ByteCodeStepOut,
+			/// <summary>
+			/// Step-in at the source level
+			/// </summary>
 			StepIn,
 			StepIn,
+			/// <summary>
+			/// Step-over at the source level
+			/// </summary>
 			StepOver,
 			StepOver,
+			/// <summary>
+			/// Step-out at the source level
+			/// </summary>
 			StepOut,
 			StepOut,
+			/// <summary>
+			/// Continue execution "freely"
+			/// </summary>
 			Run,
 			Run,
+			/// <summary>
+			/// Toggles breakpoint 
+			/// </summary>
 			ToggleBreakpoint,
 			ToggleBreakpoint,
+			/// <summary>
+			/// Sets a breakpoint
+			/// </summary>
 			SetBreakpoint,
 			SetBreakpoint,
+			/// <summary>
+			/// Clears a breakpoint
+			/// </summary>
 			ClearBreakpoint,
 			ClearBreakpoint,
+			/// <summary>
+			/// Refresh the data
+			/// </summary>
 			Refresh,
 			Refresh,
+			/// <summary>
+			/// Hard refresh of data
+			/// </summary>
 			HardRefresh,
 			HardRefresh,
+			/// <summary>
+			/// No action
+			/// </summary>
 			None,
 			None,
 		}
 		}
 
 
+		/// <summary>
+		/// The type of action
+		/// </summary>
 		public ActionType Action { get; set; }
 		public ActionType Action { get; set; }
+		/// <summary>
+		/// Gets the time stamp UTC of this action
+		/// </summary>
 		public DateTime TimeStampUTC { get; private set; }
 		public DateTime TimeStampUTC { get; private set; }
 
 
+		/// <summary>
+		/// Gets or sets the source identifier this action refers to. <see cref="Script.GetSourceCode"/>
+		/// </summary>
 		public int SourceID { get; set; }
 		public int SourceID { get; set; }
+		/// <summary>
+		/// Gets or sets the source line this action refers to.
+		/// </summary>
 		public int SourceLine { get; set; }
 		public int SourceLine { get; set; }
+		/// <summary>
+		/// Gets or sets the source column this action refers to.
+		/// </summary>
 		public int SourceCol { get; set; }
 		public int SourceCol { get; set; }
 
 
+		/// <summary>
+		/// Initializes a new instance of the <see cref="DebuggerAction"/> class.
+		/// </summary>
 		public DebuggerAction()
 		public DebuggerAction()
 		{
 		{
 			TimeStampUTC = DateTime.UtcNow;
 			TimeStampUTC = DateTime.UtcNow;
 		}
 		}
 
 
+		/// <summary>
+		/// Gets the age of this debugger action
+		/// </summary>
 		public TimeSpan Age { get { return DateTime.UtcNow - TimeStampUTC; } }
 		public TimeSpan Age { get { return DateTime.UtcNow - TimeStampUTC; } }
 
 
 
 
+		/// <summary>
+		/// Returns a <see cref="System.String" /> that represents this instance.
+		/// </summary>
+		/// <returns>
+		/// A <see cref="System.String" /> that represents this instance.
+		/// </returns>
 		public override string ToString()
 		public override string ToString()
 		{
 		{
 			if (Action == ActionType.ToggleBreakpoint || Action == ActionType.SetBreakpoint || Action == ActionType.ClearBreakpoint)
 			if (Action == ActionType.ToggleBreakpoint || Action == ActionType.SetBreakpoint || Action == ActionType.ClearBreakpoint)

+ 24 - 0
src/MoonSharp.Interpreter/Debugging/SourceCode.cs

@@ -5,13 +5,32 @@ using System.Text;
 
 
 namespace MoonSharp.Interpreter.Debugging
 namespace MoonSharp.Interpreter.Debugging
 {
 {
+	/// <summary>
+	/// Class representing the source code of a given script
+	/// </summary>
 	public class SourceCode : IScriptPrivateResource
 	public class SourceCode : IScriptPrivateResource
 	{
 	{
+		/// <summary>
+		/// Gets the name of the source code
+		/// </summary>
 		public string Name { get; private set; }
 		public string Name { get; private set; }
+		/// <summary>
+		/// Gets the source code as a string
+		/// </summary>
 		public string Code { get; private set; }
 		public string Code { get; private set; }
+		/// <summary>
+		/// Gets the source code lines.
+		/// </summary>
 		public string[] Lines { get; private set; }
 		public string[] Lines { get; private set; }
+		/// <summary>
+		/// Gets the script owning this resource.
+		/// </summary>
 		public Script OwnerScript { get; private set; }
 		public Script OwnerScript { get; private set; }
+		/// <summary>
+		/// Gets the source identifier inside a script
+		/// </summary>
 		public int SourceID { get; private set; }
 		public int SourceID { get; private set; }
+
 		internal List<SourceRef> Refs { get; private set; }
 		internal List<SourceRef> Refs { get; private set; }
 
 
 		internal SourceCode(string name, string code, int sourceID, Script ownerScript)
 		internal SourceCode(string name, string code, int sourceID, Script ownerScript)
@@ -33,6 +52,11 @@ namespace MoonSharp.Interpreter.Debugging
 			SourceID = sourceID;
 			SourceID = sourceID;
 		}
 		}
 
 
+		/// <summary>
+		/// Gets the code snippet represented by a source ref
+		/// </summary>
+		/// <param name="sourceCodeRef">The source code reference.</param>
+		/// <returns></returns>
 		public string GetCodeSnippet(SourceRef sourceCodeRef)
 		public string GetCodeSnippet(SourceRef sourceCodeRef)
 		{
 		{
 			if (sourceCodeRef.FromLine == sourceCodeRef.ToLine)
 			if (sourceCodeRef.FromLine == sourceCodeRef.ToLine)

+ 0 - 13
src/MoonSharp.Interpreter/Debugging/SourceCodeType.cs

@@ -1,13 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace MoonSharp.Interpreter.Debugging
-{
-	public enum SourceCodeType
-	{
-		Script,
-		Bytecode
-	}
-}

+ 54 - 3
src/MoonSharp.Interpreter/Debugging/SourceRef.cs

@@ -5,22 +5,50 @@ using System.Text;
 
 
 namespace MoonSharp.Interpreter.Debugging
 namespace MoonSharp.Interpreter.Debugging
 {
 {
+	/// <summary>
+	/// Class representing a reference to source code interval
+	/// </summary>
 	public class SourceRef
 	public class SourceRef
 	{
 	{
+		/// <summary>
+		/// Gets a value indicating whether this location is inside CLR .
+		/// </summary>
 		public bool IsClrLocation { get; private set; }
 		public bool IsClrLocation { get; private set; }
 
 
+		/// <summary>
+		/// Gets the index of the source.
+		/// </summary>
 		public int SourceIdx { get; private set; }
 		public int SourceIdx { get; private set; }
+		/// <summary>
+		/// Gets from which column the source code ref starts
+		/// </summary>
 		public int FromChar { get; private set; }
 		public int FromChar { get; private set; }
+		/// <summary>
+		/// Gets to which column the source code ref ends
+		/// </summary>
 		public int ToChar { get; private set; }
 		public int ToChar { get; private set; }
+		/// <summary>
+		/// Gets from which line the source code ref starts
+		/// </summary>
 		public int FromLine { get; private set; }
 		public int FromLine { get; private set; }
+		/// <summary>
+		/// Gets to which line the source code ref ends
+		/// </summary>
 		public int ToLine { get; private set; }
 		public int ToLine { get; private set; }
+		/// <summary>
+		/// Gets a value indicating whether this instance is a stop "step" in source mode
+		/// </summary>
 		public bool IsStepStop { get; private set; }
 		public bool IsStepStop { get; private set; }
 
 
+		/// <summary>
+		/// Gets a value indicating whether this instance is a breakpoint
+		/// </summary>
 		public bool Breakpoint;
 		public bool Breakpoint;
+		/// <summary>
+		/// Gets a value indicating whether this instance cannot be set as a breakpoint
+		/// </summary>
 		public bool CannotBreakpoint { get; private set; }
 		public bool CannotBreakpoint { get; private set; }
 
 
-		public string Type { get; set; }
-
 		internal static SourceRef GetClrLocation()
 		internal static SourceRef GetClrLocation()
 		{
 		{
 			return new SourceRef(0, 0, 0, 0, 0, false) { IsClrLocation = true };
 			return new SourceRef(0, 0, 0, 0, 0, false) { IsClrLocation = true };
@@ -37,6 +65,12 @@ namespace MoonSharp.Interpreter.Debugging
 		}
 		}
 
 
 
 
+		/// <summary>
+		/// Returns a <see cref="System.String" /> that represents this instance.
+		/// </summary>
+		/// <returns>
+		/// A <see cref="System.String" /> that represents this instance.
+		/// </returns>
 		public override string ToString()
 		public override string ToString()
 		{
 		{
 			return string.Format("[{0}]{1} ({2}, {3}) -> ({4}, {5})",
 			return string.Format("[{0}]{1} ({2}, {3}) -> ({4}, {5})",
@@ -45,7 +79,7 @@ namespace MoonSharp.Interpreter.Debugging
 				ToLine, ToChar);
 				ToLine, ToChar);
 		}
 		}
 
 
-		public int GetLocationDistance(int sourceIdx, int line, int col)
+		internal int GetLocationDistance(int sourceIdx, int line, int col)
 		{
 		{
 			const int PER_LINE_FACTOR = 1600; // we avoid computing real lines length and approximate with heuristics..
 			const int PER_LINE_FACTOR = 1600; // we avoid computing real lines length and approximate with heuristics..
 
 
@@ -96,6 +130,13 @@ namespace MoonSharp.Interpreter.Debugging
 			}
 			}
 		}
 		}
 
 
+		/// <summary>
+		/// Gets whether the source ref includes the specified location
+		/// </summary>
+		/// <param name="sourceIdx">Index of the source.</param>
+		/// <param name="line">The line.</param>
+		/// <param name="col">The column.</param>
+		/// <returns></returns>
 		public bool IncludesLocation(int sourceIdx, int line, int col)
 		public bool IncludesLocation(int sourceIdx, int line, int col)
 		{
 		{
 			if (sourceIdx != SourceIdx || line < FromLine || line > ToLine)
 			if (sourceIdx != SourceIdx || line < FromLine || line > ToLine)
@@ -111,12 +152,22 @@ namespace MoonSharp.Interpreter.Debugging
 			return true;
 			return true;
 		}
 		}
 
 
+		/// <summary>
+		/// Sets the CannotBreakpoint flag.
+		/// </summary>
+		/// <returns></returns>
 		public SourceRef SetNoBreakPoint()
 		public SourceRef SetNoBreakPoint()
 		{
 		{
 			CannotBreakpoint = true;
 			CannotBreakpoint = true;
 			return this;
 			return this;
 		}
 		}
 
 
+		/// <summary>
+		/// Formats the location according to script preferences
+		/// </summary>
+		/// <param name="script">The script.</param>
+		/// <param name="forceClassicFormat">if set to <c>true</c> the classic Lua format is forced.</param>
+		/// <returns></returns>
 		public string FormatLocation(Script script, bool forceClassicFormat = false)
 		public string FormatLocation(Script script, bool forceClassicFormat = false)
 		{
 		{
 			SourceCode sc = script.GetSourceCode(this.SourceIdx);
 			SourceCode sc = script.GetSourceCode(this.SourceIdx);

+ 36 - 0
src/MoonSharp.Interpreter/Debugging/WatchItem.cs

@@ -6,17 +6,53 @@ using MoonSharp.Interpreter.Execution;
 
 
 namespace MoonSharp.Interpreter.Debugging
 namespace MoonSharp.Interpreter.Debugging
 {
 {
+	/// <summary>
+	/// A watch item for the debugger to consume.
+	/// Most properties make or not sense depending on the WatchType.
+	/// </summary>
 	public class WatchItem
 	public class WatchItem
 	{
 	{
+		/// <summary>
+		/// Gets or sets the address of the item
+		/// </summary>
 		public int Address { get; set; }
 		public int Address { get; set; }
+		/// <summary>
+		/// Gets or sets the base pointer (base value of v-stack at entering the function).
+		/// Valid only for call-stack items
+		/// </summary>
 		public int BasePtr { get; set; }
 		public int BasePtr { get; set; }
+		/// <summary>
+		/// Gets or sets the return address.
+		/// Valid only for call-stack items
+		/// </summary>
 		public int RetAddress { get; set; }
 		public int RetAddress { get; set; }
+		/// <summary>
+		/// Gets or sets the name of the item
+		/// </summary>
 		public string Name { get; set; }
 		public string Name { get; set; }
+		/// <summary>
+		/// Gets or sets the value of the item
+		/// </summary>
 		public DynValue Value { get; set; }
 		public DynValue Value { get; set; }
+		/// <summary>
+		/// Gets or sets the symbol reference of the item 
+		/// </summary>
 		public SymbolRef LValue { get; set; }
 		public SymbolRef LValue { get; set; }
+		/// <summary>
+		/// Gets or sets a value indicating whether this instance is generating an error.
+		/// </summary>
 		public bool IsError { get; set; }
 		public bool IsError { get; set; }
+		/// <summary>
+		/// Gets or sets the source location this item refers to.
+		/// </summary>
 		public SourceRef Location { get; set; }
 		public SourceRef Location { get; set; }
 
 
+		/// <summary>
+		/// Returns a <see cref="System.String" /> that represents this instance.
+		/// </summary>
+		/// <returns>
+		/// A <see cref="System.String" /> that represents this instance.
+		/// </returns>
 		public override string ToString()
 		public override string ToString()
 		{
 		{
 			return string.Format("{0}:{1}:{2}:{3}:{4}:{5}",
 			return string.Format("{0}:{1}:{2}:{3}:{4}:{5}",

+ 18 - 0
src/MoonSharp.Interpreter/Debugging/WatchType.cs

@@ -5,13 +5,31 @@ using System.Text;
 
 
 namespace MoonSharp.Interpreter.Debugging
 namespace MoonSharp.Interpreter.Debugging
 {
 {
+	/// <summary>
+	/// Enumeration of the possible watch types
+	/// </summary>
 	public enum WatchType
 	public enum WatchType
 	{
 	{
+		/// <summary>
+		/// A real variable watch
+		/// </summary>
 		Watches,
 		Watches,
+		/// <summary>
+		/// The status of the v-stack
+		/// </summary>
 		VStack,
 		VStack,
+		/// <summary>
+		/// The call stack
+		/// </summary>
 		CallStack,
 		CallStack,
+		/// <summary>
+		/// The list of coroutines
+		/// </summary>
 		Coroutines,
 		Coroutines,
 
 
+		/// <summary>
+		/// The maximum value of this enum
+		/// </summary>
 		MaxValue
 		MaxValue
 	}
 	}
 }
 }

+ 1 - 1
src/MoonSharp.Interpreter/Diagnostics/PerformanceCounters/IPerformanceStopwatch.cs

@@ -5,7 +5,7 @@ using System.Text;
 
 
 namespace MoonSharp.Interpreter.Diagnostics.PerformanceCounters
 namespace MoonSharp.Interpreter.Diagnostics.PerformanceCounters
 {
 {
-	public interface IPerformanceStopwatch
+	internal interface IPerformanceStopwatch
 	{
 	{
 		IDisposable Start();
 		IDisposable Start();
 		PerformanceResult GetResult();
 		PerformanceResult GetResult();

+ 2 - 0
src/MoonSharp.Interpreter/Execution/InstructionFieldUsage.cs

@@ -69,11 +69,13 @@ namespace MoonSharp.Interpreter.Execution
 				case OpCode.Upvalue:
 				case OpCode.Upvalue:
 					return InstructionFieldUsage.Symbol;
 					return InstructionFieldUsage.Symbol;
 				case OpCode.IndexSet:
 				case OpCode.IndexSet:
+				case OpCode.IndexSetN:
 					return InstructionFieldUsage.Symbol | InstructionFieldUsage.Value | InstructionFieldUsage.NumVal | InstructionFieldUsage.NumVal2;
 					return InstructionFieldUsage.Symbol | InstructionFieldUsage.Value | InstructionFieldUsage.NumVal | InstructionFieldUsage.NumVal2;
 				case OpCode.StoreLcl:
 				case OpCode.StoreLcl:
 				case OpCode.StoreUpv:
 				case OpCode.StoreUpv:
 					return InstructionFieldUsage.Symbol | InstructionFieldUsage.NumVal | InstructionFieldUsage.NumVal2;
 					return InstructionFieldUsage.Symbol | InstructionFieldUsage.NumVal | InstructionFieldUsage.NumVal2;
 				case OpCode.Index:
 				case OpCode.Index:
+				case OpCode.IndexN:
 				case OpCode.Literal:
 				case OpCode.Literal:
 					return InstructionFieldUsage.Value;
 					return InstructionFieldUsage.Value;
 				case OpCode.Args:
 				case OpCode.Args:

+ 1 - 34
src/MoonSharp.Interpreter/Execution/Scopes/ClosureContext.cs

@@ -8,28 +8,8 @@ namespace MoonSharp.Interpreter.Execution
 	/// <summary>
 	/// <summary>
 	/// The scope of a closure (container of upvalues)
 	/// The scope of a closure (container of upvalues)
 	/// </summary>
 	/// </summary>
-	public class ClosureContext : List<DynValue>
+	internal class ClosureContext : List<DynValue>
 	{
 	{
-		/// <summary>
-		/// Type of closure based on upvalues
-		/// </summary>
-		public enum UpvaluesType
-		{
-			/// <summary>
-			/// The closure has no upvalues (thus, technically, it's a function and not a closure!)
-			/// </summary>
-			None,
-			/// <summary>
-			/// The closure has _ENV as its only upvalue
-			/// </summary>
-			Environment,
-			/// <summary>
-			/// The closure is a "real" closure, with multiple upvalues
-			/// </summary>
-			Closure
-		}
-
-
 		/// <summary>
 		/// <summary>
 		/// Gets the symbols.
 		/// Gets the symbols.
 		/// </summary>
 		/// </summary>
@@ -46,18 +26,5 @@ namespace MoonSharp.Interpreter.Execution
 			Symbols = new string[0];
 			Symbols = new string[0];
 		}
 		}
 
 
-		/// <summary>
-		/// Gets the type of the upvalues contained in this closure
-		/// </summary>
-		/// <returns></returns>
-		public UpvaluesType GetUpvaluesType()
-		{
-			if (Symbols.Length == 0)
-				return UpvaluesType.None;
-			else if (Symbols.Length == 1 && Symbols[0] == WellKnownSymbols.ENV)
-				return UpvaluesType.Environment;
-			else
-				return UpvaluesType.Closure;
-		}
 	}
 	}
 }
 }

+ 1 - 1
src/MoonSharp.Interpreter/Execution/ScriptExecutionContext.cs

@@ -6,7 +6,7 @@ using MoonSharp.Interpreter.Debugging;
 using MoonSharp.Interpreter.Execution.VM;
 using MoonSharp.Interpreter.Execution.VM;
 using MoonSharp.Interpreter.Interop.LuaStateInterop;
 using MoonSharp.Interpreter.Interop.LuaStateInterop;
 
 
-namespace MoonSharp.Interpreter.Execution
+namespace MoonSharp.Interpreter
 {
 {
 	/// <summary>
 	/// <summary>
 	/// Class giving access to details of the environment where the script is executing
 	/// Class giving access to details of the environment where the script is executing

+ 4 - 4
src/MoonSharp.Interpreter/Execution/VM/ByteCode.cs

@@ -298,14 +298,14 @@ namespace MoonSharp.Interpreter.Execution.VM
 			return AppendInstruction(new Instruction(m_CurrentSourceRef) { OpCode = OpCode.TblInitI, NumVal = lastpos ? 1 : 0 });
 			return AppendInstruction(new Instruction(m_CurrentSourceRef) { OpCode = OpCode.TblInitI, NumVal = lastpos ? 1 : 0 });
 		}
 		}
 
 
-		public Instruction Emit_Index(DynValue index = null)
+		public Instruction Emit_Index(DynValue index = null, bool isNameIndex = false)
 		{
 		{
-			return AppendInstruction(new Instruction(m_CurrentSourceRef) { OpCode = OpCode.Index, Value = index });
+			return AppendInstruction(new Instruction(m_CurrentSourceRef) { OpCode = isNameIndex ? OpCode.IndexN : OpCode.Index, Value = index });
 		}
 		}
 
 
-		public Instruction Emit_IndexSet(int stackofs, int tupleidx, DynValue index = null)
+		public Instruction Emit_IndexSet(int stackofs, int tupleidx, DynValue index = null, bool isNameIndex = false)
 		{
 		{
-			return AppendInstruction(new Instruction(m_CurrentSourceRef) { OpCode = OpCode.IndexSet, NumVal = stackofs, NumVal2 = tupleidx, Value = index });
+			return AppendInstruction(new Instruction(m_CurrentSourceRef) { OpCode = isNameIndex ? OpCode.IndexSetN : OpCode.IndexSet, NumVal = stackofs, NumVal2 = tupleidx, Value = index });
 		}
 		}
 
 
 		public Instruction Emit_Copy(int numval)
 		public Instruction Emit_Copy(int numval)

+ 2 - 0
src/MoonSharp.Interpreter/Execution/VM/OpCode.cs

@@ -24,6 +24,8 @@ namespace MoonSharp.Interpreter.Execution.VM
 		StoreLcl, Local,
 		StoreLcl, Local,
 		StoreUpv, Upvalue,
 		StoreUpv, Upvalue,
 		IndexSet, Index,
 		IndexSet, Index,
+		IndexSetN,
+		IndexN,
 
 
 		// Stack-frame ops and calls
 		// Stack-frame ops and calls
 		Clean,		// Cleansup locals setting them as null
 		Clean,		// Cleansup locals setting them as null

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

@@ -13,7 +13,7 @@ namespace MoonSharp.Interpreter.Execution.VM
 	sealed partial class Processor
 	sealed partial class Processor
 	{
 	{
 		const ulong DUMP_CHUNK_MAGIC = 0x1A0D234E4F4F4D1D;
 		const ulong DUMP_CHUNK_MAGIC = 0x1A0D234E4F4F4D1D;
-		const int DUMP_CHUNK_VERSION = 0x900;
+		const int DUMP_CHUNK_VERSION = 0x902;
 
 
 		internal static bool IsDumpStream(Stream stream)
 		internal static bool IsDumpStream(Stream stream)
 		{
 		{

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

@@ -199,10 +199,12 @@ namespace MoonSharp.Interpreter.Execution.VM
 							ExecTblInitI(i);
 							ExecTblInitI(i);
 							break;
 							break;
 						case OpCode.Index:
 						case OpCode.Index:
+						case OpCode.IndexN:
 							instructionPtr = ExecIndex(i, instructionPtr);
 							instructionPtr = ExecIndex(i, instructionPtr);
 							if (instructionPtr == YIELD_SPECIAL_TRAP) goto yield_to_calling_coroutine;
 							if (instructionPtr == YIELD_SPECIAL_TRAP) goto yield_to_calling_coroutine;
 							break;
 							break;
 						case OpCode.IndexSet:
 						case OpCode.IndexSet:
+						case OpCode.IndexSetN:
 							instructionPtr = ExecIndexSet(i, instructionPtr);
 							instructionPtr = ExecIndexSet(i, instructionPtr);
 							if (instructionPtr == YIELD_SPECIAL_TRAP) goto yield_to_calling_coroutine;
 							if (instructionPtr == YIELD_SPECIAL_TRAP) goto yield_to_calling_coroutine;
 							break;
 							break;
@@ -1143,6 +1145,8 @@ namespace MoonSharp.Interpreter.Execution.VM
 			int nestedMetaOps = 100; // sanity check, to avoid potential infinite loop here
 			int nestedMetaOps = 100; // sanity check, to avoid potential infinite loop here
 
 
 			// stack: vals.. - base - index
 			// stack: vals.. - base - index
+			bool isNameIndex = i.OpCode == OpCode.IndexSetN;
+
 			DynValue idx = i.Value ?? m_ValueStack.Pop().ToScalar();
 			DynValue idx = i.Value ?? m_ValueStack.Pop().ToScalar();
 			DynValue obj = m_ValueStack.Pop().ToScalar();
 			DynValue obj = m_ValueStack.Pop().ToScalar();
 			var value = GetStoreValue(i);
 			var value = GetStoreValue(i);
@@ -1172,7 +1176,7 @@ namespace MoonSharp.Interpreter.Execution.VM
 				{
 				{
 					UserData ud = obj.UserData;
 					UserData ud = obj.UserData;
 
 
-					if (!ud.Descriptor.SetIndex(this.GetScript(), ud.Object, idx, value))
+					if (!ud.Descriptor.SetIndex(this.GetScript(), ud.Object, idx, value, isNameIndex))
 					{
 					{
 						throw ScriptRuntimeException.UserDataMissingField(ud.Descriptor.Name, idx.String);
 						throw ScriptRuntimeException.UserDataMissingField(ud.Descriptor.Name, idx.String);
 					}
 					}
@@ -1209,6 +1213,7 @@ namespace MoonSharp.Interpreter.Execution.VM
 			int nestedMetaOps = 100; // sanity check, to avoid potential infinite loop here
 			int nestedMetaOps = 100; // sanity check, to avoid potential infinite loop here
 
 
 			// stack: base - index
 			// stack: base - index
+			bool isNameIndex = i.OpCode == OpCode.IndexN;
 			DynValue idx = i.Value ?? m_ValueStack.Pop().ToScalar();
 			DynValue idx = i.Value ?? m_ValueStack.Pop().ToScalar();
 			DynValue obj = m_ValueStack.Pop().ToScalar();
 			DynValue obj = m_ValueStack.Pop().ToScalar();
 
 
@@ -1240,7 +1245,7 @@ namespace MoonSharp.Interpreter.Execution.VM
 				{
 				{
 					UserData ud = obj.UserData;
 					UserData ud = obj.UserData;
 
 
-					var v = ud.Descriptor.Index(this.GetScript(), ud.Object, idx);
+					var v = ud.Descriptor.Index(this.GetScript(), ud.Object, idx, isNameIndex);
 
 
 					if (v == null)
 					if (v == null)
 						throw ScriptRuntimeException.UserDataMissingField(ud.Descriptor.Name, idx.String);
 						throw ScriptRuntimeException.UserDataMissingField(ud.Descriptor.Name, idx.String);

+ 7 - 1
src/MoonSharp.Interpreter/Interop/Attributes/MoonSharpUserDataAttribute.cs

@@ -5,10 +5,16 @@ using System.Text;
 
 
 namespace MoonSharp.Interpreter
 namespace MoonSharp.Interpreter
 {
 {
+	/// <summary>
+	/// Marks a type of automatic registration as userdata (which happens only if UserData.RegisterAssembly is called).
+	/// </summary>
 	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
 	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
 	public sealed class MoonSharpUserDataAttribute : Attribute
 	public sealed class MoonSharpUserDataAttribute : Attribute
 	{
 	{
-		public InteropAccessMode AccessMode { get; private set; }
+		/// <summary>
+		/// The interop access mode
+		/// </summary>
+		public InteropAccessMode AccessMode { get; set; }
 
 
 		public MoonSharpUserDataAttribute()
 		public MoonSharpUserDataAttribute()
 		{
 		{

+ 7 - 0
src/MoonSharp.Interpreter/Interop/Attributes/MoonSharpVisibleAttribute.cs

@@ -5,11 +5,18 @@ using System.Text;
 
 
 namespace MoonSharp.Interpreter.Interop
 namespace MoonSharp.Interpreter.Interop
 {
 {
+	/// <summary>
+	/// Forces a class member visibility to scripts. Can be used to hide public members or to expose non-public ones.
+	/// </summary>
 	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
 	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
 	public sealed class MoonSharpVisibleAttribute : Attribute
 	public sealed class MoonSharpVisibleAttribute : Attribute
 	{
 	{
 		public bool Visible { get; private set; }
 		public bool Visible { get; private set; }
 
 
+		/// <summary>
+		/// Initializes a new instance of the <see cref="MoonSharpVisibleAttribute"/> class.
+		/// </summary>
+		/// <param name="visible">if set to true the member will be exposed to scripts, if false the member will be hidden.</param>
 		public MoonSharpVisibleAttribute(bool visible)
 		public MoonSharpVisibleAttribute(bool visible)
 		{
 		{
 			Visible = visible;
 			Visible = visible;

+ 48 - 0
src/MoonSharp.Interpreter/Interop/Converters/ConversionHelper.cs

@@ -7,6 +7,9 @@ using MoonSharp.Interpreter.Execution;
 
 
 namespace MoonSharp.Interpreter.Interop
 namespace MoonSharp.Interpreter.Interop
 {
 {
+	/// <summary>
+	/// Handler of internal conversions between CLR and script types
+	/// </summary>
 	internal static class ConversionHelper
 	internal static class ConversionHelper
 	{
 	{
 		static readonly HashSet<Type> NumericTypes = new HashSet<Type>()
 		static readonly HashSet<Type> NumericTypes = new HashSet<Type>()
@@ -25,6 +28,9 @@ namespace MoonSharp.Interpreter.Interop
 		};
 		};
 
 
 
 
+		/// <summary>
+		/// Checks the callback signature of a method is compatible for callbacks
+		/// </summary>
 		internal static bool CheckCallbackSignature(MethodInfo mi)
 		internal static bool CheckCallbackSignature(MethodInfo mi)
 		{
 		{
 			ParameterInfo[] pi = mi.GetParameters();
 			ParameterInfo[] pi = mi.GetParameters();
@@ -33,6 +39,9 @@ namespace MoonSharp.Interpreter.Interop
 				&& pi[1].ParameterType == typeof(CallbackArguments) && mi.ReturnType == typeof(DynValue) && mi.IsPublic);
 				&& pi[1].ParameterType == typeof(CallbackArguments) && mi.ReturnType == typeof(DynValue) && mi.IsPublic);
 		}
 		}
 
 
+		/// <summary>
+		/// Tries to convert a CLR object to a MoonSharp value, using "simple" logic
+		/// </summary>
 		internal static DynValue TryClrObjectToSimpleMoonSharpValue(Script script, object obj)
 		internal static DynValue TryClrObjectToSimpleMoonSharpValue(Script script, object obj)
 		{
 		{
 			if (obj == null)
 			if (obj == null)
@@ -82,6 +91,9 @@ namespace MoonSharp.Interpreter.Interop
 		}
 		}
 
 
 
 
+		/// <summary>
+		/// Tries to convert a CLR object to a MoonSharp value, using more in-depth analysis
+		/// </summary>
 		internal static DynValue ClrObjectToComplexMoonSharpValue(Script script, object obj)
 		internal static DynValue ClrObjectToComplexMoonSharpValue(Script script, object obj)
 		{
 		{
 			DynValue v = TryClrObjectToSimpleMoonSharpValue(script, obj);
 			DynValue v = TryClrObjectToSimpleMoonSharpValue(script, obj);
@@ -138,6 +150,9 @@ namespace MoonSharp.Interpreter.Interop
 			throw ScriptRuntimeException.ConvertObjectFailed(obj);
 			throw ScriptRuntimeException.ConvertObjectFailed(obj);
 		}
 		}
 
 
+		/// <summary>
+		/// Converts an IDictionary to a Lua table.
+		/// </summary>
 		private static Table ConvertIDictionaryToTable(Script script, System.Collections.IDictionary dict)
 		private static Table ConvertIDictionaryToTable(Script script, System.Collections.IDictionary dict)
 		{
 		{
 			Table t = new Table(script);
 			Table t = new Table(script);
@@ -152,6 +167,9 @@ namespace MoonSharp.Interpreter.Interop
 			return t;
 			return t;
 		}
 		}
 
 
+		/// <summary>
+		/// Converts an IList to a Lua table.
+		/// </summary>
 		private static Table ConvertIListToTable(Script script, System.Collections.IList list)
 		private static Table ConvertIListToTable(Script script, System.Collections.IList list)
 		{
 		{
 			Table t = new Table(script);
 			Table t = new Table(script);
@@ -162,6 +180,9 @@ namespace MoonSharp.Interpreter.Interop
 			return t;
 			return t;
 		}
 		}
 
 
+		/// <summary>
+		/// Converts a DynValue to a CLR object [simple conversion]
+		/// </summary>
 		internal static object MoonSharpValueToClrObject(DynValue value)
 		internal static object MoonSharpValueToClrObject(DynValue value)
 		{
 		{
 			var converter = Script.GlobalOptions.CustomConverters.GetScriptToClrCustomConversion(value.Type, typeof(System.Object));
 			var converter = Script.GlobalOptions.CustomConverters.GetScriptToClrCustomConversion(value.Type, typeof(System.Object));
@@ -203,6 +224,9 @@ namespace MoonSharp.Interpreter.Interop
 			}
 			}
 		}
 		}
 
 
+		/// <summary>
+		/// Converts a DynValue to a CLR object of a specific type
+		/// </summary>
 		internal static object MoonSharpValueToObjectOfType(DynValue value, Type desiredType, object defaultValue)
 		internal static object MoonSharpValueToObjectOfType(DynValue value, Type desiredType, object defaultValue)
 		{
 		{
 			var converter = Script.GlobalOptions.CustomConverters.GetScriptToClrCustomConversion(value.Type, desiredType);
 			var converter = Script.GlobalOptions.CustomConverters.GetScriptToClrCustomConversion(value.Type, desiredType);
@@ -332,6 +356,9 @@ namespace MoonSharp.Interpreter.Interop
 			throw ScriptRuntimeException.ConvertObjectFailed(value.Type, desiredType);
 			throw ScriptRuntimeException.ConvertObjectFailed(value.Type, desiredType);
 		}
 		}
 
 
+		/// <summary>
+		/// Converts a table to a CLR object of a given type
+		/// </summary>
 		private static object ConvertTableToType(Table table, Type t)
 		private static object ConvertTableToType(Table table, Type t)
 		{
 		{
 			if (t.IsAssignableFrom(typeof(Dictionary<object, object>)))
 			if (t.IsAssignableFrom(typeof(Dictionary<object, object>)))
@@ -369,6 +396,9 @@ namespace MoonSharp.Interpreter.Interop
 			return null;
 			return null;
 		}
 		}
 
 
+		/// <summary>
+		/// Converts a table to a <seealso cref="Dictionary{K,V}"/>
+		/// </summary>
 		private static object ConvertTableToDictionaryOfGenericType(Type dictionaryType, Type keyType, Type valueType, Table table)
 		private static object ConvertTableToDictionaryOfGenericType(Type dictionaryType, Type keyType, Type valueType, Table table)
 		{
 		{
 			if (dictionaryType.GetGenericTypeDefinition() != typeof(Dictionary<,>))
 			if (dictionaryType.GetGenericTypeDefinition() != typeof(Dictionary<,>))
@@ -390,6 +420,9 @@ namespace MoonSharp.Interpreter.Interop
 			return dic;
 			return dic;
 		}
 		}
 
 
+		/// <summary>
+		/// Converts a table to a T[]
+		/// </summary>
 		private static object ConvertTableToArrayOfGenericType(Type arrayType, Type itemType, Table table)
 		private static object ConvertTableToArrayOfGenericType(Type arrayType, Type itemType, Table table)
 		{
 		{
 			List<object> lst = new List<object>(); 
 			List<object> lst = new List<object>(); 
@@ -410,6 +443,9 @@ namespace MoonSharp.Interpreter.Interop
 		}
 		}
 
 
 
 
+		/// <summary>
+		/// Converts a table to a <seealso cref="List{T}"/>
+		/// </summary>
 		private static object ConvertTableToListOfGenericType(Type listType, Type itemType, Table table)
 		private static object ConvertTableToListOfGenericType(Type listType, Type itemType, Table table)
 		{
 		{
 			if (listType.GetGenericTypeDefinition() != typeof(List<>))
 			if (listType.GetGenericTypeDefinition() != typeof(List<>))
@@ -430,6 +466,9 @@ namespace MoonSharp.Interpreter.Interop
 			return lst;
 			return lst;
 		}
 		}
 
 
+		/// <summary>
+		/// Converts a table to a <seealso cref="List{T}"/>, known in advance
+		/// </summary>
 		private static List<T> TableToList<T>(Table table, Func<DynValue, T> converter)
 		private static List<T> TableToList<T>(Table table, Func<DynValue, T> converter)
 		{
 		{
 			List<T> lst = new List<T>();
 			List<T> lst = new List<T>();
@@ -444,6 +483,9 @@ namespace MoonSharp.Interpreter.Interop
 			return lst;
 			return lst;
 		}
 		}
 
 
+		/// <summary>
+		/// Converts a table to a Dictionary, known in advance
+		/// </summary>
 		private static Dictionary<TK, TV> TableToDictionary<TK, TV>(Table table, Func<DynValue, TK> keyconverter, Func<DynValue, TV> valconverter)
 		private static Dictionary<TK, TV> TableToDictionary<TK, TV>(Table table, Func<DynValue, TK> keyconverter, Func<DynValue, TV> valconverter)
 		{
 		{
 			Dictionary<TK, TV> dict = new Dictionary<TK, TV>();
 			Dictionary<TK, TV> dict = new Dictionary<TK, TV>();
@@ -459,6 +501,9 @@ namespace MoonSharp.Interpreter.Interop
 			return dict;
 			return dict;
 		}
 		}
 
 
+		/// <summary>
+		/// Converts a double to another type
+		/// </summary>
 		internal static object DoubleToType(Type type, double d)
 		internal static object DoubleToType(Type type, double d)
 		{
 		{
 			type = Nullable.GetUnderlyingType(type) ?? type;
 			type = Nullable.GetUnderlyingType(type) ?? type;
@@ -477,6 +522,9 @@ namespace MoonSharp.Interpreter.Interop
 			return d;
 			return d;
 		}
 		}
 
 
+		/// <summary>
+		/// Converts a type to double
+		/// </summary>
 		internal static double TypeToDouble(Type type, object d)
 		internal static double TypeToDouble(Type type, object d)
 		{
 		{
 			if (type == typeof(double)) return (double)d;
 			if (type == typeof(double)) return (double)d;

+ 20 - 0
src/MoonSharp.Interpreter/Interop/Converters/LinqHelpers.cs

@@ -10,21 +10,41 @@ namespace MoonSharp.Interpreter
 	/// </summary>
 	/// </summary>
 	public static class LinqHelpers
 	public static class LinqHelpers
 	{
 	{
+		/// <summary>
+		/// Converts the specified enumerable dynvalues of a given script type to objects of a given type
+		/// </summary>
+		/// <typeparam name="T">The desired type</typeparam>
+		/// <param name="enumerable">The enumerable.</param>
+		/// <param name="type">The type.</param>
 		public static IEnumerable<T> Convert<T>(this IEnumerable<DynValue> enumerable, DataType type)
 		public static IEnumerable<T> Convert<T>(this IEnumerable<DynValue> enumerable, DataType type)
 		{
 		{
 			return enumerable.Where(v => v.Type == type).Select(v => v.ToObject<T>());
 			return enumerable.Where(v => v.Type == type).Select(v => v.ToObject<T>());
 		}
 		}
 
 
+		/// <summary>
+		/// Filters an enumeration for items of the given script type
+		/// </summary>
+		/// <param name="enumerable">The enumerable.</param>
+		/// <param name="type">The script type.</param>
 		public static IEnumerable<DynValue> OfDataType(this IEnumerable<DynValue> enumerable, DataType type)
 		public static IEnumerable<DynValue> OfDataType(this IEnumerable<DynValue> enumerable, DataType type)
 		{
 		{
 			return enumerable.Where(v => v.Type == type);
 			return enumerable.Where(v => v.Type == type);
 		}
 		}
 
 
+		/// <summary>
+		/// Converts the elements to CLR objects
+		/// </summary>
+		/// <param name="enumerable">The enumerable.</param>
 		public static IEnumerable<object> AsObjects(this IEnumerable<DynValue> enumerable)
 		public static IEnumerable<object> AsObjects(this IEnumerable<DynValue> enumerable)
 		{
 		{
 			return enumerable.Select(v => v.ToObject());
 			return enumerable.Select(v => v.ToObject());
 		}
 		}
 
 
+		/// <summary>
+		/// Converts the elements to CLR objects of the desired type
+		/// </summary>
+		/// <typeparam name="T">The desired type</typeparam>
+		/// <param name="enumerable">The enumerable.</param>
 		public static IEnumerable<T> AsObjects<T>(this IEnumerable<DynValue> enumerable)
 		public static IEnumerable<T> AsObjects<T>(this IEnumerable<DynValue> enumerable)
 		{
 		{
 			return enumerable.Select(v => v.ToObject<T>());
 			return enumerable.Select(v => v.ToObject<T>());

+ 41 - 2
src/MoonSharp.Interpreter/Interop/IUserDataDescriptor.cs

@@ -5,13 +5,52 @@ using System.Text;
 
 
 namespace MoonSharp.Interpreter.Interop
 namespace MoonSharp.Interpreter.Interop
 {
 {
+	/// <summary>
+	/// Interface used by MoonSharp to access objects of a given type from scripts.
+	/// </summary>
 	public interface IUserDataDescriptor
 	public interface IUserDataDescriptor
 	{
 	{
+		/// <summary>
+		/// Gets the name of the descriptor (usually, the name of the type described).
+		/// </summary>
 		string Name { get; }
 		string Name { get; }
+		/// <summary>
+		/// Gets the type this descriptor refers to
+		/// </summary>
 		Type Type { get; }
 		Type Type { get; }
-		DynValue Index(Script script, object obj, DynValue index);
-		bool SetIndex(Script script, object obj, DynValue index, DynValue value);
+		/// <summary>
+		/// Performs an "index" "get" operation.
+		/// </summary>
+		/// <param name="script">The script originating the request</param>
+		/// <param name="obj">The object (null if a static request is done)</param>
+		/// <param name="index">The index.</param>
+		/// <param name="isDirectIndexing">If set to true, it's indexed with a name, if false it's indexed through brackets.</param>
+		/// <returns></returns>
+		DynValue Index(Script script, object obj, DynValue index, bool isDirectIndexing);
+		/// <summary>
+		/// Performs an "index" "set" operation.
+		/// </summary>
+		/// <param name="script">The script originating the request</param>
+		/// <param name="obj">The object (null if a static request is done)</param>
+		/// <param name="index">The index.</param>
+		/// <param name="value">The value to be set</param>
+		/// <param name="isDirectIndexing">If set to true, it's indexed with a name, if false it's indexed through brackets.</param>
+		/// <returns></returns>
+		bool SetIndex(Script script, object obj, DynValue index, DynValue value, bool isDirectIndexing);
+		/// <summary>
+		/// Converts this userdata to string
+		/// </summary>
+		/// <param name="obj">The object.</param>
+		/// <returns></returns>
 		string AsString(object obj);
 		string AsString(object obj);
+		/// <summary>
+		/// Gets the value of an hypothetical metatable for this userdata.
+		/// NOT SUPPORTED YET.
+		/// </summary>
+		/// <param name="script">The script originating the request</param>
+		/// <param name="obj">The object (null if a static request is done)</param>
+		/// <param name="metaname">The name of the metamember.</param>
+		/// <returns></returns>
 		DynValue MetaIndex(Script script, object obj, string metaname);
 		DynValue MetaIndex(Script script, object obj, string metaname);
 	}
 	}
 }
 }

+ 29 - 2
src/MoonSharp.Interpreter/Interop/IUserDataType.cs

@@ -5,10 +5,37 @@ using System.Text;
 
 
 namespace MoonSharp.Interpreter.Interop
 namespace MoonSharp.Interpreter.Interop
 {
 {
+	/// <summary>
+	/// As a convenience, every type deriving from IUserDataType is "self-described". That is, no descriptor is needed/generated
+	/// and the object itself is used to describe the type for interop. See also <seealso cref="UserData"/>, <seealso cref="IUserDataDescriptor"/> 
+	/// and <seealso cref="StandardUserDataDescriptor"/> .
+	/// </summary>
 	public interface IUserDataType
 	public interface IUserDataType
 	{
 	{
-		DynValue Index(Script script, DynValue index);
-		bool SetIndex(Script script, DynValue index, DynValue value);
+		/// <summary>
+		/// Performs an "index" "get" operation.
+		/// </summary>
+		/// <param name="script">The script originating the request</param>
+		/// <param name="index">The index.</param>
+		/// <param name="isDirectIndexing">If set to true, it's indexed with a name, if false it's indexed through brackets.</param>
+		/// <returns></returns>
+		DynValue Index(Script script, DynValue index, bool isDirectIndexing);
+		/// <summary>
+		/// Performs an "index" "set" operation.
+		/// </summary>
+		/// <param name="script">The script originating the request</param>
+		/// <param name="index">The index.</param>
+		/// <param name="value">The value to be set</param>
+		/// <param name="isDirectIndexing">If set to true, it's indexed with a name, if false it's indexed through brackets.</param>
+		/// <returns></returns>
+		bool SetIndex(Script script, DynValue index, DynValue value, bool isDirectIndexing);
+		/// <summary>
+		/// Gets the value of an hypothetical metatable for this userdata.
+		/// NOT SUPPORTED YET.
+		/// </summary>
+		/// <param name="script">The script originating the request</param>
+		/// <param name="metaname">The name of the metamember.</param>
+		/// <returns></returns>
 		DynValue MetaIndex(Script script, string metaname);
 		DynValue MetaIndex(Script script, string metaname);
 	}
 	}
 }
 }

+ 3 - 0
src/MoonSharp.Interpreter/Interop/InteropAccessMode.cs

@@ -8,6 +8,9 @@ namespace MoonSharp.Interpreter
 	/// <summary>
 	/// <summary>
 	/// Enumerations of the possible strategies to marshal CLR objects to MoonSharp userdata and functions
 	/// Enumerations of the possible strategies to marshal CLR objects to MoonSharp userdata and functions
 	/// when using automatic descriptors.
 	/// when using automatic descriptors.
+	/// Note that these are "hints" and MoonSharp is free to ignore the access mode specified (if different from
+	/// HideMembers) and downgrade the access mode to "Reflection". 
+	/// This particularly happens when running on AOT platforms like iOS.
 	/// See also : <seealso cref="CallbackFunction"/> and <seealso cref="UserData"/> .
 	/// See also : <seealso cref="CallbackFunction"/> and <seealso cref="UserData"/> .
 	/// </summary>
 	/// </summary>
 	public enum InteropAccessMode
 	public enum InteropAccessMode

+ 8 - 0
src/MoonSharp.Interpreter/Interop/PredefinedUserData/AnonWrapper.cs

@@ -5,10 +5,18 @@ using System.Text;
 
 
 namespace MoonSharp.Interpreter.Interop
 namespace MoonSharp.Interpreter.Interop
 {
 {
+	/// <summary>
+	/// Internal type used by <seealso cref="AnonWrapper{T}"/> for registration
+	/// </summary>
 	public class AnonWrapper
 	public class AnonWrapper
 	{
 	{
 	}
 	}
 
 
+	/// <summary>
+	/// Wrapper which allows for easier management of userdata without registering a new userdata type - useful 
+	/// if a type which is not exposed to scripts but can be managed as a "black box" by scripts is desired.
+	/// </summary>
+	/// <typeparam name="T">The type to wrap</typeparam>
 	public class AnonWrapper<T> : AnonWrapper
 	public class AnonWrapper<T> : AnonWrapper
 	{
 	{
 		public AnonWrapper()
 		public AnonWrapper()

+ 3 - 0
src/MoonSharp.Interpreter/Interop/PredefinedUserData/EnumerableWrapper.cs

@@ -7,6 +7,9 @@ using MoonSharp.Interpreter.Execution;
 
 
 namespace MoonSharp.Interpreter.Interop
 namespace MoonSharp.Interpreter.Interop
 {
 {
+	/// <summary>
+	/// Wrappers for enumerables as return types
+	/// </summary>
 	internal class EnumerableWrapper
 	internal class EnumerableWrapper
 	{
 	{
 		IEnumerator m_Enumerator;
 		IEnumerator m_Enumerator;

+ 4 - 4
src/MoonSharp.Interpreter/Interop/StandardDescriptors/AutoDescribingUserDataDescriptor.cs

@@ -27,22 +27,22 @@ namespace MoonSharp.Interpreter
 			get { return m_Type; }
 			get { return m_Type; }
 		}
 		}
 
 
-		public DynValue Index(Script script, object obj, DynValue index)
+		public DynValue Index(Script script, object obj, DynValue index, bool isNameIndex)
 		{
 		{
 			IUserDataType u = obj as IUserDataType;
 			IUserDataType u = obj as IUserDataType;
 
 
 			if (u != null)
 			if (u != null)
-				return u.Index(script, index);
+				return u.Index(script, index, isNameIndex);
 
 
 			return null;
 			return null;
 		}
 		}
 
 
-		public bool SetIndex(Script script, object obj, DynValue index, DynValue value)
+		public bool SetIndex(Script script, object obj, DynValue index, DynValue value, bool isNameIndex)
 		{
 		{
 			IUserDataType u = obj as IUserDataType;
 			IUserDataType u = obj as IUserDataType;
 
 
 			if (u != null)
 			if (u != null)
-				return u.SetIndex(script, index, value);
+				return u.SetIndex(script, index, value, isNameIndex);
 
 
 			return false;
 			return false;
 		}
 		}

+ 4 - 4
src/MoonSharp.Interpreter/Interop/StandardDescriptors/CompositeUserDataDescriptor.cs

@@ -26,11 +26,11 @@ namespace MoonSharp.Interpreter.Interop
 			get { return m_Type; }
 			get { return m_Type; }
 		}
 		}
 
 
-		public DynValue Index(Script script, object obj, DynValue index)
+		public DynValue Index(Script script, object obj, DynValue index, bool isNameIndex)
 		{
 		{
 			foreach (IUserDataDescriptor dd in m_Descriptors)
 			foreach (IUserDataDescriptor dd in m_Descriptors)
 			{
 			{
-				DynValue v = dd.Index(script, obj, index);
+				DynValue v = dd.Index(script, obj, index, isNameIndex);
 
 
 				if (v != null)
 				if (v != null)
 					return v;
 					return v;
@@ -38,11 +38,11 @@ namespace MoonSharp.Interpreter.Interop
 			return null;
 			return null;
 		}
 		}
 
 
-		public bool SetIndex(Script script, object obj, DynValue index, DynValue value)
+		public bool SetIndex(Script script, object obj, DynValue index, DynValue value, bool isNameIndex)
 		{
 		{
 			foreach (IUserDataDescriptor dd in m_Descriptors)
 			foreach (IUserDataDescriptor dd in m_Descriptors)
 			{
 			{
-				if (dd.SetIndex(script, obj, index, value))
+				if (dd.SetIndex(script, obj, index, value, isNameIndex))
 					return true;
 					return true;
 			}
 			}
 			return false;
 			return false;

+ 78 - 2
src/MoonSharp.Interpreter/Interop/StandardDescriptors/StandardUserDataDescriptor.cs

@@ -8,16 +8,37 @@ using MoonSharp.Interpreter.Execution;
 
 
 namespace MoonSharp.Interpreter.Interop
 namespace MoonSharp.Interpreter.Interop
 {
 {
+	/// <summary>
+	/// Standard descriptor for userdata types.
+	/// </summary>
 	public class StandardUserDataDescriptor : IUserDataDescriptor
 	public class StandardUserDataDescriptor : IUserDataDescriptor
 	{
 	{
+		/// <summary>
+		/// Gets the name of the descriptor (usually, the name of the type described).
+		/// </summary>
 		public string Name { get; private set; }
 		public string Name { get; private set; }
+		/// <summary>
+		/// Gets the type this descriptor refers to
+		/// </summary>
 		public Type Type { get; private set; }
 		public Type Type { get; private set; }
+		/// <summary>
+		/// Gets the interop access mode this descriptor uses for members access
+		/// </summary>
 		public InteropAccessMode AccessMode { get; private set; }
 		public InteropAccessMode AccessMode { get; private set; }
+		/// <summary>
+		/// Gets a human readable friendly name of the descriptor
+		/// </summary>
 		public string FriendlyName { get; private set; }
 		public string FriendlyName { get; private set; }
 
 
 		private Dictionary<string, StandardUserDataMethodDescriptor> m_Methods = new Dictionary<string, StandardUserDataMethodDescriptor>();
 		private Dictionary<string, StandardUserDataMethodDescriptor> m_Methods = new Dictionary<string, StandardUserDataMethodDescriptor>();
 		private Dictionary<string, StandardUserDataPropertyDescriptor> m_Properties = new Dictionary<string, StandardUserDataPropertyDescriptor>();
 		private Dictionary<string, StandardUserDataPropertyDescriptor> m_Properties = new Dictionary<string, StandardUserDataPropertyDescriptor>();
 
 
+		/// <summary>
+		/// Initializes a new instance of the <see cref="StandardUserDataDescriptor"/> class.
+		/// </summary>
+		/// <param name="type">The type this descriptor refers to.</param>
+		/// <param name="accessMode">The interop access mode this descriptor uses for members access</param>
+		/// <param name="friendlyName">A human readable friendly name of the descriptor.</param>
 		protected internal StandardUserDataDescriptor(Type type, InteropAccessMode accessMode, string friendlyName)
 		protected internal StandardUserDataDescriptor(Type type, InteropAccessMode accessMode, string friendlyName)
 		{
 		{
 			if (Script.GlobalOptions.Platform.IsRunningOnAOT())
 			if (Script.GlobalOptions.Platform.IsRunningOnAOT())
@@ -90,7 +111,15 @@ namespace MoonSharp.Interpreter.Interop
 		}
 		}
 
 
 
 
-		public DynValue Index(Script script, object obj, DynValue index)
+		/// <summary>
+		/// Performs an "index" "get" operation. This tries to resolve minor variations of member names.
+		/// </summary>
+		/// <param name="script">The script originating the request</param>
+		/// <param name="obj">The object (null if a static request is done)</param>
+		/// <param name="index">The index.</param>
+		/// <param name="isDirectIndexing">If set to true, it's indexed with a name, if false it's indexed through brackets.</param>
+		/// <returns></returns>
+		public DynValue Index(Script script, object obj, DynValue index, bool isDirectIndexing)
 		{
 		{
 			if (index.Type != DataType.String)
 			if (index.Type != DataType.String)
 				throw ScriptRuntimeException.BadArgument(1, string.Format("userdata<{0}>.__index", this.Name), "string", index.Type.ToLuaTypeString(), false);
 				throw ScriptRuntimeException.BadArgument(1, string.Format("userdata<{0}>.__index", this.Name), "string", index.Type.ToLuaTypeString(), false);
@@ -103,6 +132,13 @@ namespace MoonSharp.Interpreter.Interop
 			return v;
 			return v;
 		}
 		}
 
 
+		/// <summary>
+		/// Tries to perform an indexing operation by checking methods and properties for the given indexName
+		/// </summary>
+		/// <param name="script">The script.</param>
+		/// <param name="obj">The object.</param>
+		/// <param name="indexName">Member name to be indexed.</param>
+		/// <returns></returns>
 		protected virtual DynValue TryIndex(Script script, object obj, string indexName)
 		protected virtual DynValue TryIndex(Script script, object obj, string indexName)
 		{
 		{
 			StandardUserDataMethodDescriptor mdesc;
 			StandardUserDataMethodDescriptor mdesc;
@@ -121,7 +157,16 @@ namespace MoonSharp.Interpreter.Interop
 			return null;
 			return null;
 		}
 		}
 
 
-		public bool SetIndex(Script script, object obj, DynValue index, DynValue value)
+		/// <summary>
+		/// Performs an "index" "set" operation. This tries to resolve minor variations of member names.
+		/// </summary>
+		/// <param name="script">The script originating the request</param>
+		/// <param name="obj">The object (null if a static request is done)</param>
+		/// <param name="index">The index.</param>
+		/// <param name="value">The value to be set</param>
+		/// <param name="isDirectIndexing">If set to true, it's indexed with a name, if false it's indexed through brackets.</param>
+		/// <returns></returns>
+		public bool SetIndex(Script script, object obj, DynValue index, DynValue value, bool isDirectIndexing)
 		{
 		{
 			if (index.Type != DataType.String)
 			if (index.Type != DataType.String)
 				throw ScriptRuntimeException.BadArgument(1, string.Format("userdata<{0}>.__setindex", this.Name), "string", index.Type.ToLuaTypeString(), false);
 				throw ScriptRuntimeException.BadArgument(1, string.Format("userdata<{0}>.__setindex", this.Name), "string", index.Type.ToLuaTypeString(), false);
@@ -134,6 +179,14 @@ namespace MoonSharp.Interpreter.Interop
 			return v;
 			return v;
 		}
 		}
 
 
+		/// <summary>
+		/// Tries to perform an indexing "set" operation by checking methods and properties for the given indexName
+		/// </summary>
+		/// <param name="script">The script.</param>
+		/// <param name="obj">The object.</param>
+		/// <param name="indexName">Member name to be indexed.</param>
+		/// <param name="value">The value.</param>
+		/// <returns></returns>
 		protected virtual bool TrySetIndex(Script script, object obj, string indexName, DynValue value)
 		protected virtual bool TrySetIndex(Script script, object obj, string indexName, DynValue value)
 		{
 		{
 			StandardUserDataPropertyDescriptor pdesc;
 			StandardUserDataPropertyDescriptor pdesc;
@@ -163,6 +216,11 @@ namespace MoonSharp.Interpreter.Interop
 
 
 		}
 		}
 
 
+		/// <summary>
+		/// Converts the specified name from underscore_case to camelCase.
+		/// </summary>
+		/// <param name="name">The name.</param>
+		/// <returns></returns>
 		protected static string Camelify(string name)
 		protected static string Camelify(string name)
 		{
 		{
 			StringBuilder sb = new StringBuilder(name.Length);
 			StringBuilder sb = new StringBuilder(name.Length);
@@ -188,6 +246,11 @@ namespace MoonSharp.Interpreter.Interop
 			return sb.ToString();
 			return sb.ToString();
 		}
 		}
 
 
+		/// <summary>
+		/// Converts the specified name to one with an uppercase first letter (something to Something).
+		/// </summary>
+		/// <param name="name">The name.</param>
+		/// <returns></returns>
 		protected static  string UpperFirstLetter(string name)
 		protected static  string UpperFirstLetter(string name)
 		{
 		{
 			if (!string.IsNullOrEmpty(name))
 			if (!string.IsNullOrEmpty(name))
@@ -196,11 +259,24 @@ namespace MoonSharp.Interpreter.Interop
 			return name;
 			return name;
 		}
 		}
 
 
+		/// <summary>
+		/// Converts this userdata to string
+		/// </summary>
+		/// <param name="obj">The object.</param>
+		/// <returns></returns>
 		public string AsString(object obj)
 		public string AsString(object obj)
 		{
 		{
 			return (obj != null) ? obj.ToString() : null;
 			return (obj != null) ? obj.ToString() : null;
 		}
 		}
 
 
+		/// <summary>
+		/// Gets the value of an hypothetical metatable for this userdata.
+		/// NOT SUPPORTED YET.
+		/// </summary>
+		/// <param name="script">The script originating the request</param>
+		/// <param name="obj">The object (null if a static request is done)</param>
+		/// <param name="metaname">The name of the metamember.</param>
+		/// <returns></returns>
 		public DynValue MetaIndex(Script script, object obj, string metaname)
 		public DynValue MetaIndex(Script script, object obj, string metaname)
 		{
 		{
 			// TODO: meta access to overloaded operators ?
 			// TODO: meta access to overloaded operators ?

+ 66 - 9
src/MoonSharp.Interpreter/Interop/StandardDescriptors/StandardUserDataMethodDescriptor.cs

@@ -10,12 +10,30 @@ using MoonSharp.Interpreter.Execution;
 
 
 namespace MoonSharp.Interpreter.Interop
 namespace MoonSharp.Interpreter.Interop
 {
 {
+	/// <summary>
+	/// Class providing easier marshalling of CLR functions
+	/// </summary>
 	public class StandardUserDataMethodDescriptor
 	public class StandardUserDataMethodDescriptor
 	{
 	{
+		/// <summary>
+		/// Gets the method information (can be a MethodInfo or ConstructorInfo)
+		/// </summary>
 		public MethodBase MethodInfo { get; private set; }
 		public MethodBase MethodInfo { get; private set; }
+		/// <summary>
+		/// Gets the access mode used for interop
+		/// </summary>
 		public InteropAccessMode AccessMode { get; private set; }
 		public InteropAccessMode AccessMode { get; private set; }
+		/// <summary>
+		/// Gets a value indicating whether the described method is static.
+		/// </summary>
 		public bool IsStatic { get; private set; }
 		public bool IsStatic { get; private set; }
+		/// <summary>
+		/// Gets the name of the described method
+		/// </summary>
 		public string Name { get; private set; }
 		public string Name { get; private set; }
+		/// <summary>
+		/// Gets a value indicating whether the described method is a constructor
+		/// </summary>
 		public bool IsConstructor { get; private set; }
 		public bool IsConstructor { get; private set; }
 
 
 		private Type[] m_Arguments;
 		private Type[] m_Arguments;
@@ -24,7 +42,13 @@ namespace MoonSharp.Interpreter.Interop
 		private Action<object, object[]> m_OptimizedAction = null;
 		private Action<object, object[]> m_OptimizedAction = null;
 		private bool m_IsAction = false;
 		private bool m_IsAction = false;
 
 
-		public StandardUserDataMethodDescriptor(MethodBase mi, InteropAccessMode accessMode = InteropAccessMode.Default)
+		/// <summary>
+		/// Initializes a new instance of the <see cref="StandardUserDataMethodDescriptor"/> class.
+		/// </summary>
+		/// <param name="methodBase">The MethodBase (MethodInfo or ConstructorInfo) got through reflection.</param>
+		/// <param name="accessMode">The interop access mode.</param>
+		/// <exception cref="System.ArgumentException">Invalid accessMode</exception>
+		public StandardUserDataMethodDescriptor(MethodBase methodBase, InteropAccessMode accessMode = InteropAccessMode.Default)
 		{
 		{
 			if (Script.GlobalOptions.Platform.IsRunningOnAOT())
 			if (Script.GlobalOptions.Platform.IsRunningOnAOT())
 				accessMode = InteropAccessMode.Reflection;
 				accessMode = InteropAccessMode.Reflection;
@@ -35,51 +59,84 @@ namespace MoonSharp.Interpreter.Interop
 			if (accessMode == InteropAccessMode.HideMembers)
 			if (accessMode == InteropAccessMode.HideMembers)
 				throw new ArgumentException("Invalid accessMode");
 				throw new ArgumentException("Invalid accessMode");
 
 
-			this.MethodInfo = mi;
+			this.MethodInfo = methodBase;
 			this.AccessMode = accessMode;
 			this.AccessMode = accessMode;
-			this.Name = mi.Name;
+			this.Name = methodBase.Name;
 
 
-			IsConstructor = (mi is ConstructorInfo);
+			IsConstructor = (methodBase is ConstructorInfo);
 
 
-			this.IsStatic = mi.IsStatic || IsConstructor; // we consider the constructor to be a static method as far interop is concerned.
+			this.IsStatic = methodBase.IsStatic || IsConstructor; // we consider the constructor to be a static method as far interop is concerned.
 
 
-			if (mi is ConstructorInfo)
+			if (methodBase is ConstructorInfo)
 			{
 			{
 				m_IsAction = false;
 				m_IsAction = false;
 			}
 			}
 			else
 			else
 			{
 			{
-				m_IsAction = ((MethodInfo)mi).ReturnType == typeof(void);
+				m_IsAction = ((MethodInfo)methodBase).ReturnType == typeof(void);
 			}
 			}
 
 
-			m_Arguments = mi.GetParameters().Select(pi => pi.ParameterType).ToArray();
-			m_Defaults = mi.GetParameters().Select(pi => pi.DefaultValue).ToArray();
+			m_Arguments = methodBase.GetParameters().Select(pi => pi.ParameterType).ToArray();
+			m_Defaults = methodBase.GetParameters().Select(pi => pi.DefaultValue).ToArray();
 
 
 			if (AccessMode == InteropAccessMode.Preoptimized)
 			if (AccessMode == InteropAccessMode.Preoptimized)
 				Optimize();
 				Optimize();
 		}
 		}
 
 
+		/// <summary>
+		/// Gets a callback function as a delegate
+		/// </summary>
+		/// <param name="script">The script for which the callback must be generated.</param>
+		/// <param name="obj">The object (null for static).</param>
+		/// <returns></returns>
 		public Func<ScriptExecutionContext, CallbackArguments, DynValue> GetCallback(Script script, object obj = null)
 		public Func<ScriptExecutionContext, CallbackArguments, DynValue> GetCallback(Script script, object obj = null)
 		{
 		{
 			return (c, a) => Callback(script, obj, c, a);
 			return (c, a) => Callback(script, obj, c, a);
 		}
 		}
 
 
+		/// <summary>
+		/// Gets the callback function.
+		/// </summary>
+		/// <param name="script">The script for which the callback must be generated.</param>
+		/// <param name="obj">The object (null for static).</param>
+		/// <returns></returns>
 		public CallbackFunction GetCallbackFunction(Script script, object obj = null)
 		public CallbackFunction GetCallbackFunction(Script script, object obj = null)
 		{
 		{
 			return new CallbackFunction(GetCallback(script, obj), this.Name);
 			return new CallbackFunction(GetCallback(script, obj), this.Name);
 		}
 		}
 
 
+		/// <summary>
+		/// Gets the callback function as a DynValue.
+		/// </summary>
+		/// <param name="script">The script for which the callback must be generated.</param>
+		/// <param name="obj">The object (null for static).</param>
+		/// <returns></returns>
 		public DynValue GetCallbackAsDynValue(Script script, object obj = null)
 		public DynValue GetCallbackAsDynValue(Script script, object obj = null)
 		{
 		{
 			return DynValue.NewCallback(this.GetCallbackFunction(script, obj));
 			return DynValue.NewCallback(this.GetCallbackFunction(script, obj));
 		}
 		}
 
 
+		/// <summary>
+		/// Creates a callback DynValue starting from a MethodInfo.
+		/// </summary>
+		/// <param name="script">The script.</param>
+		/// <param name="mi">The mi.</param>
+		/// <param name="obj">The object.</param>
+		/// <returns></returns>
 		public static DynValue CreateCallbackDynValue(Script script, MethodInfo mi, object obj = null)
 		public static DynValue CreateCallbackDynValue(Script script, MethodInfo mi, object obj = null)
 		{
 		{
 			var desc = new StandardUserDataMethodDescriptor(mi);
 			var desc = new StandardUserDataMethodDescriptor(mi);
 			return desc.GetCallbackAsDynValue(script, obj);
 			return desc.GetCallbackAsDynValue(script, obj);
 		}
 		}
 
 
+		/// <summary>
+		/// The internal callback which actually executes the method
+		/// </summary>
+		/// <param name="script">The script.</param>
+		/// <param name="obj">The object.</param>
+		/// <param name="context">The context.</param>
+		/// <param name="args">The arguments.</param>
+		/// <returns></returns>
 		DynValue Callback(Script script, object obj, ScriptExecutionContext context, CallbackArguments args)
 		DynValue Callback(Script script, object obj, ScriptExecutionContext context, CallbackArguments args)
 		{
 		{
 			if (AccessMode == InteropAccessMode.LazyOptimized &&
 			if (AccessMode == InteropAccessMode.LazyOptimized &&

+ 3 - 0
src/MoonSharp.Interpreter/Interop/StandardDescriptors/StandardUserDataPropertyDescriptor.cs

@@ -9,6 +9,9 @@ using MoonSharp.Interpreter.Diagnostics;
 
 
 namespace MoonSharp.Interpreter.Interop
 namespace MoonSharp.Interpreter.Interop
 {
 {
+	/// <summary>
+	/// Class providing easier marshalling of CLR properties
+	/// </summary>
 	internal class StandardUserDataPropertyDescriptor
 	internal class StandardUserDataPropertyDescriptor
 	{
 	{
 		internal PropertyInfo PropertyInfo { get; private set; }
 		internal PropertyInfo PropertyInfo { get; private set; }

+ 3 - 0
src/MoonSharp.Interpreter/Loaders/ScriptLoaderBase.cs

@@ -6,6 +6,9 @@ using System.Text;
 
 
 namespace MoonSharp.Interpreter.Loaders
 namespace MoonSharp.Interpreter.Loaders
 {
 {
+	/// <summary>
+	/// A base implementation of IScriptLoader, offering resolution of module names.
+	/// </summary>
 	public abstract class ScriptLoaderBase : IScriptLoader
 	public abstract class ScriptLoaderBase : IScriptLoader
 	{
 	{
 		/// <summary>
 		/// <summary>

+ 4 - 1
src/MoonSharp.Interpreter/Loaders/UnityAssetsScriptLoader.cs

@@ -9,7 +9,10 @@ namespace MoonSharp.Interpreter.Loaders
 {
 {
 	/// <summary>
 	/// <summary>
 	/// A script loader which can load scripts from assets in Unity3D.
 	/// A script loader which can load scripts from assets in Unity3D.
-	/// Scripts should be saved as .txt files in a subdirectory of Assets/Resources
+	/// Scripts should be saved as .txt files in a subdirectory of Assets/Resources.
+	/// 
+	/// When MoonSharp is activated on Unity3D and the default script loader is used,
+	/// scripts should be saved as .txt files in Assets/Resources/MoonSharp/Scripts.
 	/// </summary>
 	/// </summary>
 	public class UnityAssetsScriptLoader : ScriptLoaderBase
 	public class UnityAssetsScriptLoader : ScriptLoaderBase
 	{
 	{

+ 1 - 1
src/MoonSharp.Interpreter/Modules/CoreModules.cs

@@ -100,7 +100,7 @@ namespace MoonSharp.Interpreter
 
 
 	}
 	}
 
 
-	public static class CoreModules_ExtensionMethods
+	internal static class CoreModules_ExtensionMethods
 	{
 	{
 		public static bool Has(this CoreModules val, CoreModules flag)
 		public static bool Has(this CoreModules val, CoreModules flag)
 		{
 		{

+ 25 - 6
src/MoonSharp.Interpreter/Modules/ModuleRegister.cs

@@ -48,6 +48,11 @@ namespace MoonSharp.Interpreter
 
 
 
 
 
 
+		/// <summary>
+		/// Registers the standard constants (_G, _VERSION, _MOONSHARP) to a table
+		/// </summary>
+		/// <param name="table">The table.</param>
+		/// <returns></returns>
 		public static Table RegisterConstants(this Table table)
 		public static Table RegisterConstants(this Table table)
 		{
 		{
 			DynValue moonsharp_table = DynValue.NewTable(table.OwnerScript);
 			DynValue moonsharp_table = DynValue.NewTable(table.OwnerScript);
@@ -71,15 +76,22 @@ namespace MoonSharp.Interpreter
 
 
 
 
 
 
+		/// <summary>
+		/// Registers a module type to the specified table
+		/// </summary>
+		/// <param name="gtable">The table.</param>
+		/// <param name="t">The type</param>
+		/// <returns></returns>
+		/// <exception cref="System.ArgumentException">If the module contains some incompatibility</exception>
 		public static Table RegisterModuleType(this Table gtable, Type t)
 		public static Table RegisterModuleType(this Table gtable, Type t)
 		{
 		{
 			Table table = CreateModuleNamespace(gtable, t);
 			Table table = CreateModuleNamespace(gtable, t);
 
 
 			foreach (MethodInfo mi in t.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
 			foreach (MethodInfo mi in t.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
 			{
 			{
-				if (mi.GetCustomAttributes(typeof(MoonSharpMethodAttribute), false).Length > 0)
+				if (mi.GetCustomAttributes(typeof(MoonSharpModuleMethodAttribute), false).Length > 0)
 				{
 				{
-					MoonSharpMethodAttribute attr = (MoonSharpMethodAttribute)mi.GetCustomAttributes(typeof(MoonSharpMethodAttribute), false).First();
+					MoonSharpModuleMethodAttribute attr = (MoonSharpModuleMethodAttribute)mi.GetCustomAttributes(typeof(MoonSharpModuleMethodAttribute), false).First();
 
 
 					if (!ConversionHelper.CheckCallbackSignature(mi))
 					if (!ConversionHelper.CheckCallbackSignature(mi))
 							throw new ArgumentException(string.Format("Method {0} does not have the right signature.", mi.Name));
 							throw new ArgumentException(string.Format("Method {0} does not have the right signature.", mi.Name));
@@ -97,16 +109,16 @@ namespace MoonSharp.Interpreter
 				}
 				}
 			}
 			}
 
 
-			foreach (FieldInfo fi in t.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).Where(_mi => _mi.GetCustomAttributes(typeof(MoonSharpMethodAttribute), false).Length > 0))
+			foreach (FieldInfo fi in t.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).Where(_mi => _mi.GetCustomAttributes(typeof(MoonSharpModuleMethodAttribute), false).Length > 0))
 			{
 			{
-				MoonSharpMethodAttribute attr = (MoonSharpMethodAttribute)fi.GetCustomAttributes(typeof(MoonSharpMethodAttribute), false).First();
+				MoonSharpModuleMethodAttribute attr = (MoonSharpModuleMethodAttribute)fi.GetCustomAttributes(typeof(MoonSharpModuleMethodAttribute), false).First();
 				string name = (!string.IsNullOrEmpty(attr.Name)) ? attr.Name : fi.Name;
 				string name = (!string.IsNullOrEmpty(attr.Name)) ? attr.Name : fi.Name;
 
 
 				RegisterScriptField(fi, null, table, t, name);
 				RegisterScriptField(fi, null, table, t, name);
 			}
 			}
-			foreach (FieldInfo fi in t.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).Where(_mi => _mi.GetCustomAttributes(typeof(MoonSharpConstantAttribute), false).Length > 0))
+			foreach (FieldInfo fi in t.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).Where(_mi => _mi.GetCustomAttributes(typeof(MoonSharpModuleConstantAttribute), false).Length > 0))
 			{
 			{
-				MoonSharpConstantAttribute attr = (MoonSharpConstantAttribute)fi.GetCustomAttributes(typeof(MoonSharpConstantAttribute), false).First();
+				MoonSharpModuleConstantAttribute attr = (MoonSharpModuleConstantAttribute)fi.GetCustomAttributes(typeof(MoonSharpModuleConstantAttribute), false).First();
 				string name = (!string.IsNullOrEmpty(attr.Name)) ? attr.Name : fi.Name;
 				string name = (!string.IsNullOrEmpty(attr.Name)) ? attr.Name : fi.Name;
 
 
 				RegisterScriptFieldAsConst(fi, null, table, t, name);
 				RegisterScriptFieldAsConst(fi, null, table, t, name);
@@ -194,6 +206,13 @@ namespace MoonSharp.Interpreter
 			}
 			}
 		}
 		}
 
 
+		/// <summary>
+		/// Registers a module type to the specified table
+		/// </summary>
+		/// <typeparam name="T">The module type</typeparam>
+		/// <param name="table">The table.</param>
+		/// <returns></returns>
+		/// <exception cref="System.ArgumentException">If the module contains some incompatibility</exception>
 		public static Table RegisterModuleType<T>(this Table table)
 		public static Table RegisterModuleType<T>(this Table table)
 		{
 		{
 			return RegisterModuleType(table, typeof(T));
 			return RegisterModuleType(table, typeof(T));

+ 0 - 13
src/MoonSharp.Interpreter/Modules/MoonSharpConstantAttribute.cs

@@ -1,13 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace MoonSharp.Interpreter
-{
-	[AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
-	public sealed class MoonSharpConstantAttribute : Attribute
-	{
-		public string Name { get; set; }
-	}
-}

+ 0 - 13
src/MoonSharp.Interpreter/Modules/MoonSharpMethodAttribute.cs

@@ -1,13 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace MoonSharp.Interpreter
-{
-	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
-	public sealed class MoonSharpMethodAttribute : Attribute
-	{
-		public string Name { get; set; }
-	}
-}

+ 15 - 0
src/MoonSharp.Interpreter/Modules/MoonSharpModuleAttribute.cs

@@ -5,6 +5,21 @@ using System.Text;
 
 
 namespace MoonSharp.Interpreter
 namespace MoonSharp.Interpreter
 {
 {
+	/// <summary>
+	/// Marks a CLR type to be a MoonSharp module.
+	/// Modules are the fastest way to bring interop between scripts and CLR code, albeit at the cost of a very increased
+	/// complexity in writing them. Modules is what's used for the standard library, for maximum efficiency.
+	/// 
+	/// Modules are basically classes containing only static methods, with the callback function signature.
+	/// 
+	/// See <seealso cref="Table"/> and <seealso cref="ModuleRegister"/> for (extension) methods used to register modules to a 
+	/// table.
+	/// 
+	/// See <seealso cref="CallbackFunction"/> for information regarding the standard callback signature along with easier ways
+	/// to marshal methods.
+	/// 
+	/// See <seealso cref="UserData"/> for easier object marshalling.
+	/// </summary>
 	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
 	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
 	public sealed class MoonSharpModuleAttribute : Attribute
 	public sealed class MoonSharpModuleAttribute : Attribute
 	{
 	{

+ 18 - 0
src/MoonSharp.Interpreter/Modules/MoonSharpModuleConstantAttribute.cs

@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace MoonSharp.Interpreter
+{
+	/// <summary>
+	/// In a module type, mark fields with this attribute to have them exposed as a module constant.
+	/// 
+	/// See <seealso cref="MoonSharpModuleAttribute"/> for more information about modules.
+	/// </summary>
+	[AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
+	public sealed class MoonSharpModuleConstantAttribute : Attribute
+	{
+		public string Name { get; set; }
+	}
+}

+ 23 - 0
src/MoonSharp.Interpreter/Modules/MoonSharpModuleMethodAttribute.cs

@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace MoonSharp.Interpreter
+{
+	/// <summary>
+	/// In a module type, mark methods or fields with this attribute to have them exposed as module functions.
+	/// Methods must have the signature "public static DynValue ...(ScriptExecutionContextCallbackArguments)".
+	/// Fields must be static or const strings, with an anonymous Lua function inside.
+	/// 
+	/// See <seealso cref="MoonSharpModuleAttribute"/> for more information about modules.
+	/// </summary>
+	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
+	public sealed class MoonSharpModuleMethodAttribute : Attribute
+	{
+		/// <summary>
+		/// Gets or sets the name of the function in the module (defaults to member name)
+		/// </summary>
+		public string Name { get; set; }
+	}
+}

+ 3 - 3
src/MoonSharp.Interpreter/MoonSharp.Interpreter.net35-client.csproj

@@ -132,7 +132,6 @@
     <Compile Include="DataTypes\YieldRequest.cs" />
     <Compile Include="DataTypes\YieldRequest.cs" />
     <Compile Include="Debugging\DebuggerAction.cs" />
     <Compile Include="Debugging\DebuggerAction.cs" />
     <Compile Include="Debugging\IDebugger.cs" />
     <Compile Include="Debugging\IDebugger.cs" />
-    <Compile Include="Debugging\SourceCodeType.cs" />
     <Compile Include="Debugging\SourceRef.cs" />
     <Compile Include="Debugging\SourceRef.cs" />
     <Compile Include="Debugging\WatchItem.cs" />
     <Compile Include="Debugging\WatchItem.cs" />
     <Compile Include="Debugging\WatchType.cs" />
     <Compile Include="Debugging\WatchType.cs" />
@@ -205,7 +204,8 @@
     <Compile Include="Loaders\ScriptLoaderBase.cs" />
     <Compile Include="Loaders\ScriptLoaderBase.cs" />
     <Compile Include="Loaders\IScriptLoader.cs" />
     <Compile Include="Loaders\IScriptLoader.cs" />
     <Compile Include="Loaders\UnityAssetsScriptLoader.cs" />
     <Compile Include="Loaders\UnityAssetsScriptLoader.cs" />
-    <Compile Include="Modules\MoonSharpConstantAttribute.cs" />
+    <Compile Include="Modules\MoonSharpModuleConstantAttribute.cs" />
+    <Compile Include="NameSpace_XmlHelp.cs" />
     <Compile Include="Platforms\IPlatformAccessor.cs" />
     <Compile Include="Platforms\IPlatformAccessor.cs" />
     <Compile Include="Platforms\PlatformAccessorBase.cs" />
     <Compile Include="Platforms\PlatformAccessorBase.cs" />
     <Compile Include="Platforms\PlatformAutoDetector.cs" />
     <Compile Include="Platforms\PlatformAutoDetector.cs" />
@@ -234,7 +234,7 @@
     <Compile Include="Modules\ModuleRegister.cs">
     <Compile Include="Modules\ModuleRegister.cs">
       <SubType>Code</SubType>
       <SubType>Code</SubType>
     </Compile>
     </Compile>
-    <Compile Include="Modules\MoonSharpMethodAttribute.cs" />
+    <Compile Include="Modules\MoonSharpModuleMethodAttribute.cs" />
     <Compile Include="Modules\MoonSharpModuleAttribute.cs">
     <Compile Include="Modules\MoonSharpModuleAttribute.cs">
       <SubType>Code</SubType>
       <SubType>Code</SubType>
     </Compile>
     </Compile>

+ 1 - 1
src/MoonSharp.Interpreter/Platforms/IPlatformAccessor.cs

@@ -11,7 +11,7 @@ namespace MoonSharp.Interpreter.Platforms
 	/// Can be used both to support "non-standard" platforms (i.e. non-posix, non-windows) and/or to sandbox the behaviour
 	/// Can be used both to support "non-standard" platforms (i.e. non-posix, non-windows) and/or to sandbox the behaviour
 	/// of the scripting engine.
 	/// of the scripting engine.
 	/// 
 	/// 
-	/// It's recommended that no class implement IPlatformAccessor directly, and rather extend PlatformAccessorBase.
+	/// It's recommended that no class implement IPlatformAccessor directly, and rather extend <see cref="PlatformAccessorBase"/>.
 	/// </summary>
 	/// </summary>
 	public interface IPlatformAccessor
 	public interface IPlatformAccessor
 	{
 	{

+ 3 - 3
src/MoonSharp.Interpreter/Script.cs

@@ -255,13 +255,13 @@ namespace MoonSharp.Interpreter
 			if (!stream.CanWrite)
 			if (!stream.CanWrite)
 				throw new ArgumentException("stream is readonly!");
 				throw new ArgumentException("stream is readonly!");
 
 
-			ClosureContext.UpvaluesType upvaluesType = function.Function.ClosureContext.GetUpvaluesType();
+			Closure.UpvaluesType upvaluesType = function.Function.GetUpvaluesType();
 
 
-			if (upvaluesType == ClosureContext.UpvaluesType.Closure)
+			if (upvaluesType == Closure.UpvaluesType.Closure)
 				throw new ArgumentException("function arg has upvalues other than _ENV");
 				throw new ArgumentException("function arg has upvalues other than _ENV");
 
 
 			UndisposableStream outStream = new UndisposableStream(stream);
 			UndisposableStream outStream = new UndisposableStream(stream);
-			m_MainProcessor.Dump(outStream, function.Function.EntryPointByteCodeLocation, upvaluesType == ClosureContext.UpvaluesType.Environment);
+			m_MainProcessor.Dump(outStream, function.Function.EntryPointByteCodeLocation, upvaluesType == Closure.UpvaluesType.Environment);
 		}
 		}
 
 
 
 

+ 4 - 0
src/MoonSharp.Interpreter/ScriptGlobalOptions.cs

@@ -7,6 +7,10 @@ using MoonSharp.Interpreter.Platforms;
 
 
 namespace MoonSharp.Interpreter
 namespace MoonSharp.Interpreter
 {
 {
+	/// <summary>
+	/// Class containing script global options, that is options which cannot be customized per-script.
+	/// <see cref="Script.GlobalOptions"/>
+	/// </summary>
 	public class ScriptGlobalOptions
 	public class ScriptGlobalOptions
 	{
 	{
 		internal ScriptGlobalOptions()
 		internal ScriptGlobalOptions()

+ 1 - 2
src/MoonSharp.Interpreter/Tree/Expression_.cs

@@ -161,8 +161,7 @@ namespace MoonSharp.Interpreter.Tree
 						{
 						{
 							lcontext.Lexer.Next();
 							lcontext.Lexer.Next();
 							Token name = CheckTokenType(lcontext, TokenType.Name);
 							Token name = CheckTokenType(lcontext, TokenType.Name);
-							LiteralExpression le = new LiteralExpression(lcontext, DynValue.NewString(name.Text));
-							e = new IndexExpression(e, le, lcontext);
+							e = new IndexExpression(e, name.Text, lcontext);
 						}
 						}
 						break;
 						break;
 					case TokenType.Brk_Open_Square:
 					case TokenType.Brk_Open_Square:

+ 1 - 1
src/MoonSharp.Interpreter/Tree/Expressions/FunctionCallExpression.cs

@@ -74,7 +74,7 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 			if (!string.IsNullOrEmpty(m_Name))
 			if (!string.IsNullOrEmpty(m_Name))
 			{
 			{
 				bc.Emit_Copy(0);
 				bc.Emit_Copy(0);
-				bc.Emit_Index(DynValue.NewString(m_Name));
+				bc.Emit_Index(DynValue.NewString(m_Name), true);
 				bc.Emit_Swap(0, 1);
 				bc.Emit_Swap(0, 1);
 				++argslen;
 				++argslen;
 			}
 			}

+ 19 - 5
src/MoonSharp.Interpreter/Tree/Expressions/IndexExpression.cs

@@ -11,6 +11,7 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 	{
 	{
 		Expression m_BaseExp;
 		Expression m_BaseExp;
 		Expression m_IndexExp;
 		Expression m_IndexExp;
+		string m_Name;
 
 
 
 
 		public IndexExpression(Expression baseExp, Expression indexExp, ScriptLoadingContext lcontext)
 		public IndexExpression(Expression baseExp, Expression indexExp, ScriptLoadingContext lcontext)
@@ -20,12 +21,23 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 			m_IndexExp = indexExp;
 			m_IndexExp = indexExp;
 		}
 		}
 
 
+		public IndexExpression(Expression baseExp, string name, ScriptLoadingContext lcontext)
+			: base(lcontext)
+		{
+			m_BaseExp = baseExp;
+			m_Name = name;
+		}
+
 
 
 		public override void Compile(ByteCode bc)
 		public override void Compile(ByteCode bc)
 		{
 		{
 			m_BaseExp.Compile(bc);
 			m_BaseExp.Compile(bc);
 
 
-			if (m_IndexExp is LiteralExpression)
+			if (m_Name != null)
+			{
+				bc.Emit_Index(DynValue.NewString(m_Name), true);
+			}
+			else if (m_IndexExp is LiteralExpression)
 			{
 			{
 				LiteralExpression lit = (LiteralExpression)m_IndexExp;
 				LiteralExpression lit = (LiteralExpression)m_IndexExp;
 				bc.Emit_Index(lit.Value);
 				bc.Emit_Index(lit.Value);
@@ -41,7 +53,11 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 		{
 		{
 			m_BaseExp.Compile(bc);
 			m_BaseExp.Compile(bc);
 
 
-			if (m_IndexExp is LiteralExpression)
+			if (m_Name != null)
+			{
+				bc.Emit_IndexSet(stackofs, tupleidx, DynValue.NewString(m_Name), true);
+			}
+			else if (m_IndexExp is LiteralExpression)
 			{
 			{
 				LiteralExpression lit = (LiteralExpression)m_IndexExp;
 				LiteralExpression lit = (LiteralExpression)m_IndexExp;
 				bc.Emit_IndexSet(stackofs, tupleidx, lit.Value);
 				bc.Emit_IndexSet(stackofs, tupleidx, lit.Value);
@@ -51,14 +67,12 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 				m_IndexExp.Compile(bc);
 				m_IndexExp.Compile(bc);
 				bc.Emit_IndexSet(stackofs, tupleidx);
 				bc.Emit_IndexSet(stackofs, tupleidx);
 			}
 			}
-
-
 		}
 		}
 
 
 		public override DynValue Eval(ScriptExecutionContext context)
 		public override DynValue Eval(ScriptExecutionContext context)
 		{
 		{
 			DynValue b = m_BaseExp.Eval(context).ToScalar();
 			DynValue b = m_BaseExp.Eval(context).ToScalar();
-			DynValue i = m_IndexExp.Eval(context).ToScalar();
+			DynValue i = m_IndexExp != null ? m_IndexExp.Eval(context).ToScalar() : DynValue.NewString(m_Name);
 
 
 			if (b.Type != DataType.Table) throw new DynamicExpressionException("Attempt to index non-table.");
 			if (b.Type != DataType.Table) throw new DynamicExpressionException("Attempt to index non-table.");
 			else if (i.IsNilOrNan()) throw new DynamicExpressionException("Attempt to index with nil or nan key.");
 			else if (i.IsNilOrNan()) throw new DynamicExpressionException("Attempt to index with nil or nan key.");

+ 0 - 6
src/MoonSharp.Interpreter/Tree/NodeBase.cs

@@ -37,12 +37,6 @@ namespace MoonSharp.Interpreter.Tree
 		//	return BuildSourceRef(terminalNode.Symbol, terminalNode);
 		//	return BuildSourceRef(terminalNode.Symbol, terminalNode);
 		//}
 		//}
 
 
-		private SourceRef RegisterSourceRef(SourceRef sourceRef)
-		{
-			LoadingContext.Source.Refs.Add(sourceRef);
-			sourceRef.Type = this.GetType().Name;
-			return sourceRef;
-		}
 
 
 		protected static Token CheckTokenType(ScriptLoadingContext lcontext, TokenType tokenType)
 		protected static Token CheckTokenType(ScriptLoadingContext lcontext, TokenType tokenType)
 		{
 		{

+ 4 - 7
src/MoonSharp.Interpreter/Tree/Statements/FunctionDefinitionStatement.cs

@@ -119,16 +119,13 @@ namespace MoonSharp.Interpreter.Tree.Statements
 
 
 			foreach (string str in m_TableAccessors)
 			foreach (string str in m_TableAccessors)
 			{
 			{
-				bc.Emit_Literal(DynValue.NewString(str));
-				bc.Emit_Index();
-				cnt += 2;
+				bc.Emit_Index(DynValue.NewString(str), true);
+				cnt += 1;
 			}
 			}
 
 
-			bc.Emit_Literal(DynValue.NewString(m_MethodName));
+			bc.Emit_IndexSet(0, 0, DynValue.NewString(m_MethodName), true);
 
 
-			bc.Emit_IndexSet(0, 0);
-
-			return 2 + cnt;
+			return 1 + cnt;
 		}
 		}
 
 
 		private int SetFunction(Execution.VM.ByteCode bc, int numPop)
 		private int SetFunction(Execution.VM.ByteCode bc, int numPop)

+ 7 - 7
src/MoonSharp.Interpreter/_Projects/MoonSharp.Interpreter.net40-client/MoonSharp.Interpreter.net40-client.csproj

@@ -204,9 +204,6 @@
     <Compile Include="..\..\Debugging\IDebugger.cs">
     <Compile Include="..\..\Debugging\IDebugger.cs">
       <Link>IDebugger.cs</Link>
       <Link>IDebugger.cs</Link>
     </Compile>
     </Compile>
-    <Compile Include="..\..\Debugging\SourceCodeType.cs">
-      <Link>SourceCodeType.cs</Link>
-    </Compile>
     <Compile Include="..\..\Debugging\SourceRef.cs">
     <Compile Include="..\..\Debugging\SourceRef.cs">
       <Link>SourceRef.cs</Link>
       <Link>SourceRef.cs</Link>
     </Compile>
     </Compile>
@@ -393,8 +390,11 @@
     <Compile Include="..\..\Loaders\UnityAssetsScriptLoader.cs">
     <Compile Include="..\..\Loaders\UnityAssetsScriptLoader.cs">
       <Link>UnityAssetsScriptLoader.cs</Link>
       <Link>UnityAssetsScriptLoader.cs</Link>
     </Compile>
     </Compile>
-    <Compile Include="..\..\Modules\MoonSharpConstantAttribute.cs">
-      <Link>MoonSharpConstantAttribute.cs</Link>
+    <Compile Include="..\..\Modules\MoonSharpModuleConstantAttribute.cs">
+      <Link>MoonSharpModuleConstantAttribute.cs</Link>
+    </Compile>
+    <Compile Include="..\..\NameSpace_XmlHelp.cs">
+      <Link>NameSpace_XmlHelp.cs</Link>
     </Compile>
     </Compile>
     <Compile Include="..\..\Platforms\IPlatformAccessor.cs">
     <Compile Include="..\..\Platforms\IPlatformAccessor.cs">
       <Link>IPlatformAccessor.cs</Link>
       <Link>IPlatformAccessor.cs</Link>
@@ -470,8 +470,8 @@
       <SubType>Code</SubType>
       <SubType>Code</SubType>
       <Link>ModuleRegister.cs</Link>
       <Link>ModuleRegister.cs</Link>
     </Compile>
     </Compile>
-    <Compile Include="..\..\Modules\MoonSharpMethodAttribute.cs">
-      <Link>MoonSharpMethodAttribute.cs</Link>
+    <Compile Include="..\..\Modules\MoonSharpModuleMethodAttribute.cs">
+      <Link>MoonSharpModuleMethodAttribute.cs</Link>
     </Compile>
     </Compile>
     <Compile Include="..\..\Modules\MoonSharpModuleAttribute.cs">
     <Compile Include="..\..\Modules\MoonSharpModuleAttribute.cs">
       <SubType>Code</SubType>
       <SubType>Code</SubType>

+ 7 - 7
src/MoonSharp.Interpreter/_Projects/MoonSharp.Interpreter.portable40/MoonSharp.Interpreter.portable40.csproj

@@ -201,9 +201,6 @@
     <Compile Include="..\..\Debugging\IDebugger.cs">
     <Compile Include="..\..\Debugging\IDebugger.cs">
       <Link>IDebugger.cs</Link>
       <Link>IDebugger.cs</Link>
     </Compile>
     </Compile>
-    <Compile Include="..\..\Debugging\SourceCodeType.cs">
-      <Link>SourceCodeType.cs</Link>
-    </Compile>
     <Compile Include="..\..\Debugging\SourceRef.cs">
     <Compile Include="..\..\Debugging\SourceRef.cs">
       <Link>SourceRef.cs</Link>
       <Link>SourceRef.cs</Link>
     </Compile>
     </Compile>
@@ -390,8 +387,11 @@
     <Compile Include="..\..\Loaders\UnityAssetsScriptLoader.cs">
     <Compile Include="..\..\Loaders\UnityAssetsScriptLoader.cs">
       <Link>UnityAssetsScriptLoader.cs</Link>
       <Link>UnityAssetsScriptLoader.cs</Link>
     </Compile>
     </Compile>
-    <Compile Include="..\..\Modules\MoonSharpConstantAttribute.cs">
-      <Link>MoonSharpConstantAttribute.cs</Link>
+    <Compile Include="..\..\Modules\MoonSharpModuleConstantAttribute.cs">
+      <Link>MoonSharpModuleConstantAttribute.cs</Link>
+    </Compile>
+    <Compile Include="..\..\NameSpace_XmlHelp.cs">
+      <Link>NameSpace_XmlHelp.cs</Link>
     </Compile>
     </Compile>
     <Compile Include="..\..\Platforms\IPlatformAccessor.cs">
     <Compile Include="..\..\Platforms\IPlatformAccessor.cs">
       <Link>IPlatformAccessor.cs</Link>
       <Link>IPlatformAccessor.cs</Link>
@@ -467,8 +467,8 @@
       <SubType>Code</SubType>
       <SubType>Code</SubType>
       <Link>ModuleRegister.cs</Link>
       <Link>ModuleRegister.cs</Link>
     </Compile>
     </Compile>
-    <Compile Include="..\..\Modules\MoonSharpMethodAttribute.cs">
-      <Link>MoonSharpMethodAttribute.cs</Link>
+    <Compile Include="..\..\Modules\MoonSharpModuleMethodAttribute.cs">
+      <Link>MoonSharpModuleMethodAttribute.cs</Link>
     </Compile>
     </Compile>
     <Compile Include="..\..\Modules\MoonSharpModuleAttribute.cs">
     <Compile Include="..\..\Modules\MoonSharpModuleAttribute.cs">
       <SubType>Code</SubType>
       <SubType>Code</SubType>