Browse Source

rawget/rawset

Xanathar 11 years ago
parent
commit
75011dbe56

+ 33 - 0
src/MoonSharp.Interpreter/CoreLib/RawTableAccess.cs

@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using MoonSharp.Interpreter.Execution;
+
+namespace MoonSharp.Interpreter.CoreLib
+{
+	[MoonSharpModule]
+	public class RawTableAccess
+	{
+		[MoonSharpMethod]
+		static DynValue rawget(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			DynValue table = args.AsType(0, "rawget", DataType.Table);
+			DynValue index = args[1];
+
+			return table.Table[index];
+		}
+
+		[MoonSharpMethod]
+		static DynValue rawset(ScriptExecutionContext executionContext, CallbackArguments args)
+		{
+			DynValue table = args.AsType(0, "rawset", DataType.Table);
+			DynValue index = args[1];
+			DynValue val = args[2];
+
+			table.Table[index] = val;
+
+			return table;
+		}
+	}
+}

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

@@ -14,12 +14,13 @@ namespace MoonSharp.Interpreter
 		String = 0x8,
 		LoadMethods = 0x10,
 		Table = 0x20,
+		RawTableAccess = 0x40,
 
 
 
 		Preset_HardSandbox = GlobalConsts | TableIterators | String | Table,
 		Preset_SoftSandbox = Preset_HardSandbox | Metatables,
-		Preset_Default = Preset_SoftSandbox | LoadMethods,
+		Preset_Default = Preset_SoftSandbox | LoadMethods | RawTableAccess,
 		Preset_Complete = Preset_Default,
 
 	}

+ 1 - 0
src/MoonSharp.Interpreter/Modules/ModuleRegister.cs

@@ -19,6 +19,7 @@ namespace MoonSharp.Interpreter
 			if (modules.Has(CoreModules.LoadMethods)) RegisterModuleType<LoadMethods>(table);
 			if (modules.Has(CoreModules.Table)) RegisterModuleType<TableModule>(table);
 			if (modules.Has(CoreModules.Table)) RegisterModuleType<TableModule_Globals>(table);
+			if (modules.Has(CoreModules.RawTableAccess)) RegisterModuleType<RawTableAccess>(table);
 
 			return table;
 		}

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

@@ -89,6 +89,7 @@
     <Compile Include="CoreLib\Patterns\PatternMatching.cs">
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="CoreLib\RawTableAccess.cs" />
     <Compile Include="CoreLib\StringModule.cs" />
     <Compile Include="CoreLib\TableIterators.cs" />
     <Compile Include="CoreLib\TableModule.cs" />