├── .gitattributes ├── .gitignore ├── Readme.markdown ├── buildnuget.bat ├── nuget └── AluminumLua.nuspec ├── premake4.lua ├── src ├── AssemblyInfo.cs ├── Executors │ ├── CompilerExecutor.cs │ ├── DefaultExecutor.cs │ ├── ExpressionTrees │ │ ├── ExpressionCompiler.cs │ │ └── ExpressionVisitor.cs │ ├── IExecutor.cs │ └── InterpreterExecutor.cs ├── Libraries │ ├── BasicLibrary.cs │ └── IoLibrary.cs ├── LinkedDictionary.cs ├── LuaContext.cs ├── LuaObject.cs ├── LuaParser.cs ├── LuaSettings.cs └── Main.cs ├── test ├── dofile.lua ├── dofile.lua.txt ├── functionscopes.lua ├── functionscopes.lua.txt ├── helloworld.lua └── helloworld.lua.txt ├── test_action.lua └── vs2010 ├── .nuget └── packages.config ├── AluminiumLua.Any └── AluminiumLua.Any.csproj ├── AluminiumLua.WindowsPhone ├── AluminiumLua.wp8.csproj └── Properties │ └── AssemblyInfo.cs ├── AluminiumLua.wp71 └── AluminiumLua.wp71.csproj ├── AluminumLua.Net40 ├── AluminiumLua.snk └── AluminumLua.Net40.csproj ├── AluminumLua.Tests ├── AluminumLua.Tests.csproj ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── Tests.cs ├── packages.config └── test.lua ├── AluminumLua.sl5 ├── AluminiumLua.snk └── AluminumLua.sl5.csproj ├── AluminumLua.sln └── packages └── repositories.config /.gitattributes: -------------------------------------------------------------------------------- 1 | 2 | # Explicitly declare text files we want to always be normalized and converted 3 | # to native line endings on checkout. 4 | *.cs text 5 | *.lua text 6 | *.txt text 7 | *.markdown text 8 | 9 | # Declare files that will always have CRLF line endings on checkout. 10 | *.bat text eol=crlf 11 | *.sln text eol=crlf 12 | *.csproj text eol=crlf 13 | *.config text eol=crlf 14 | 15 | *.snk binary 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs) 4 | [Bb]in/ 5 | [Oo]bj/ 6 | 7 | # NuGet Packages Directory 8 | packages 9 | *.nupkg 10 | 11 | *.pidb 12 | *.userdata 13 | *.userprefs 14 | *.suo 15 | */_ReSharper.* 16 | *.cache 17 | *.user 18 | vs2010/AluminumLua.Tests/bin/ 19 | nuget/lib/ 20 | .dll 21 | -------------------------------------------------------------------------------- /Readme.markdown: -------------------------------------------------------------------------------- 1 | AluminumLua 2 | =========== 3 | 4 | What? 5 | ----- 6 | 7 | A fast, lightweight Lua scripting engine written entirely in C#. It's called 'AluminumLua' (or 'alua' for short) as a poke at all those "iron" languages... 8 | 9 | Architecture 10 | ------------ 11 | 12 | AluminumLua does not use the DLR. Instead of generating an AST, the parser calls directly into an interface (IExecutor), that represents abstracted stack-based execution actions, such as Assignment or function Call. 13 | 14 | This design enables different pluggable execution backends. Currently there is an InterpreterExecutor that directly executes the actions while the script is being parsed, and a CompilerExecutor that compiles a DynamicMethod. 15 | 16 | The default execution policy uses the interpreter for the main script body and generates DynamicMethods for any defined function bodies. 17 | 18 | Dependencies 19 | ------------ 20 | 21 | .NET 4.0+ is required on Windows, or Mono 2.10+ anywhere else. There are no other dependencies. 22 | 23 | Embed it 24 | -------- 25 | 26 | var context = new LuaContext (); 27 | context.AddBasicLibrary (); 28 | context.AddIoLibrary (); 29 | 30 | context.SetGlobal ("some_func_in_lua", calls_this_func_in_csharp); 31 | context.SetGlobal ("random_string", "hello"); 32 | // ... 33 | 34 | var parser = new LuaParser (context, file_name); // < or leave file_name out to read stdin 35 | parser.Parse (); 36 | 37 | 38 | 39 | Building 40 | -------- 41 | 42 | Use Premake to generate a makefile or Visual Studio solution. 43 | Get it here: http://industriousone.com/premake/download 44 | 45 | ### GNU Make ### 46 | 47 | premake4 gmake 48 | make 49 | 50 | ### Visual Studio / Xamarin Studio / MonoDevelop / SharpDevelop ### 51 | 52 | premake4 vs2010 53 | (build the solution using your favorite tool) 54 | 55 | The build produces the following products: 56 | 57 | + **AluminumLua.dll** is the script engine that can be referenced in other projects. 58 | + **alua.exe** is the command line interpreter. Pass a script file name or no arguments for a REPL. 59 | 60 | Both products are self-contained and do not depend on the other. 61 | 62 | After the Build 63 | --------------- 64 | 65 | ### Run tests ### 66 | 67 | premake4 test 68 | 69 | ### Clean ### 70 | 71 | premake4 clean 72 | 73 | License 74 | ------- 75 | MIT/X11 76 | -------------------------------------------------------------------------------- /buildnuget.bat: -------------------------------------------------------------------------------- 1 | cd nuget 2 | ..\vs2010\packages\NuGet.CommandLine.2.6.1\tools\NuGet.exe pack AluminumLua.nuspec -------------------------------------------------------------------------------- /nuget/AluminumLua.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AluminumLua 5 | 1.0.0.7 6 | AluminumLua 7 | chkn 8 | gleblebedev 9 | https://github.com/gleblebedev/AluminumLua 10 | false 11 | A fast, lightweight Lua scripting engine written entirely in C#. 12 | 13 | Copyright 2012 chkn 14 | Lua 15 | 16 | -------------------------------------------------------------------------------- /premake4.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- AluminumLua build configuration 3 | -- 4 | 5 | solution "AluminumLua" 6 | language "C#" 7 | framework "4.0" 8 | configurations { "Release", "Debug" } 9 | 10 | project "AluminumLua" 11 | kind "SharedLib" 12 | links { 13 | "System", 14 | "System.Core" 15 | } 16 | 17 | files { 18 | "src/**.cs" 19 | } 20 | 21 | excludes { 22 | "src/Main.cs" 23 | } 24 | 25 | configuration { "Debug*" } 26 | defines { "DEBUG" } 27 | flags { "Symbols" } 28 | 29 | configuration { "Release" } 30 | flags { "Optimize" } 31 | 32 | project "alua" 33 | kind "ConsoleApp" 34 | links { 35 | "System", 36 | "System.Core" 37 | } 38 | 39 | files { 40 | "src/**.cs" 41 | } 42 | 43 | configuration { "Debug*" } 44 | defines { "DEBUG" } 45 | flags { "Symbols" } 46 | 47 | configuration { "Release" } 48 | flags { "Optimize" } 49 | 50 | 51 | -- add test action 52 | dofile "test_action.lua" 53 | 54 | -- make sure all products are removed on clean 55 | if _ACTION == "clean" then 56 | mdbs = os.matchfiles "*.mdb" 57 | for _,file in ipairs (mdbs) do 58 | os.remove (file) 59 | end 60 | end 61 | -------------------------------------------------------------------------------- /src/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System.Reflection; 4 | using System.Runtime.CompilerServices; 5 | 6 | // Information about this assembly is defined by the following attributes. 7 | // Change them to the values specific to your project. 8 | 9 | [assembly: AssemblyTitle("AluminumLua")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyProduct("")] 14 | [assembly: AssemblyCopyright("")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 19 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 20 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 21 | 22 | [assembly: AssemblyVersion("1.0.0.7")] 23 | 24 | // The following attributes are used to specify the signing key for the assembly, 25 | // if desired. See the Mono documentation for more information about signing. 26 | 27 | //[assembly: AssemblyDelaySign(false)] 28 | //[assembly: AssemblyKeyFile("")] 29 | -------------------------------------------------------------------------------- /src/Executors/CompilerExecutor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | CompilerExecutor.cs: Compiles the code into a LuaFunction 3 | 4 | Copyright (c) 2011 Alexander Corrado 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | #if DEBUG_WRITE_IL 26 | #warning DEBUG_WRITE_IL is defined. This will quit after writing the first function to Debug_IL_Output.dll. 27 | #endif 28 | 29 | using System; 30 | using System.Collections.Generic; 31 | using System.Reflection; 32 | using System.Reflection.Emit; 33 | using System.Linq.Expressions; 34 | 35 | using AluminumLua.Executors.ExpressionTrees; 36 | 37 | namespace AluminumLua.Executors { 38 | 39 | using LuaTable = IDictionary; 40 | using LuaTableItem = KeyValuePair; 41 | 42 | public class CompilerExecutor : IExecutor { 43 | 44 | // all non-typesafe reflection here please 45 | private static readonly ConstructorInfo New_LuaContext = typeof (LuaContext).GetConstructor (new Type [] { typeof (LuaContext) }); 46 | private static readonly MethodInfo LuaContext_Get = typeof (LuaContext).GetMethod ("Get"); 47 | private static readonly MethodInfo LuaContext_SetLocal = typeof (LuaContext).GetMethod ("SetLocal", new Type [] { typeof (string), typeof (LuaObject) }); 48 | private static readonly MethodInfo LuaContext_SetGlobal = typeof (LuaContext).GetMethod ("SetGlobal", new Type [] { typeof (string), typeof (LuaObject) }); 49 | 50 | private static readonly FieldInfo LuaObject_Nil = typeof (LuaObject).GetField ("Nil", BindingFlags.Public | BindingFlags.Static); 51 | private static readonly MethodInfo LuaObject_FromString = typeof (LuaObject).GetMethod ("FromString", BindingFlags.Public | BindingFlags.Static); 52 | private static readonly MethodInfo LuaObject_FromNumber = typeof (LuaObject).GetMethod ("FromNumber", BindingFlags.Public | BindingFlags.Static); 53 | private static readonly MethodInfo LuaObject_FromBool = typeof (LuaObject).GetMethod ("FromBool", BindingFlags.Public | BindingFlags.Static); 54 | 55 | private static readonly MethodInfo LuaObject_AsString = typeof (LuaObject).GetMethod ("AsString"); 56 | private static readonly MethodInfo LuaObject_AsBool = typeof (LuaObject).GetMethod ("AsBool"); 57 | private static readonly MethodInfo LuaObject_AsNumber = typeof (LuaObject).GetMethod ("AsNumber"); 58 | private static readonly MethodInfo LuaObject_AsFunction = typeof (LuaObject).GetMethod ("AsFunction"); 59 | 60 | private static readonly MethodInfo LuaObject_Equals = typeof(LuaObject).GetMethod("Equals", new Type[] {typeof(LuaObject)}); 61 | 62 | private static readonly MethodInfo LuaFunction_Invoke = typeof (LuaFunction).GetMethod ("Invoke"); 63 | 64 | private static readonly MethodInfo LuaObject_this_get = typeof (LuaObject).GetProperty ("Item").GetGetMethod (); 65 | private static readonly MethodInfo LuaObject_this_set = typeof (LuaObject).GetProperty ("Item").GetSetMethod (); 66 | 67 | private static readonly MethodInfo LuaObject_NewTable = typeof (LuaObject).GetMethod ("NewTable", BindingFlags.Public | BindingFlags.Static); 68 | private static readonly ConstructorInfo New_LuaTableItem = typeof (LuaTableItem).GetConstructor (new Type [] { typeof (LuaObject), typeof (LuaObject) }); 69 | 70 | private static readonly MethodInfo String_Concat = typeof (string).GetMethod ("Concat", new Type [] { typeof (string), typeof (string) }); 71 | 72 | #if DEBUG_WRITE_IL 73 | private static AssemblyBuilder asm; 74 | private static TypeBuilder typ; 75 | #else 76 | private DynamicMethod method; 77 | #endif 78 | 79 | private LuaFunction compiled; 80 | 81 | protected Stack scopes; 82 | protected Stack stack; 83 | protected ILGenerator IL; 84 | 85 | protected ExpressionCompiler expression_compiler; 86 | protected ParameterExpression ctx, args; 87 | 88 | 89 | public LuaContext CurrentScope { get { return scopes.Peek (); } } 90 | 91 | public CompilerExecutor (LuaContext ctx) 92 | { 93 | #if DEBUG_WRITE_IL 94 | if (asm == null) { 95 | asm = AppDomain.CurrentDomain.DefineDynamicAssembly (new AssemblyName ("DebugIL"), AssemblyBuilderAccess.RunAndSave); 96 | var mod = asm.DefineDynamicModule ("Debug_IL_Output.dll", "Debug_IL_Output.dll", true); 97 | typ = mod.DefineType ("DummyType"); 98 | } 99 | var method = typ.DefineMethod ("dyn-" + Guid.NewGuid (), MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard, typeof (LuaObject), new Type [] { typeof (LuaContext), typeof (LuaObject[]) }); 100 | #else 101 | this.method = new DynamicMethod ("dyn-" + Guid.NewGuid (), typeof (LuaObject), new Type [] { typeof (LuaContext), typeof (LuaObject[]) }); 102 | #endif 103 | this.scopes = new Stack (); 104 | this.scopes.Push (ctx); 105 | 106 | this.stack = new Stack (); 107 | this.IL = method.GetILGenerator (); 108 | 109 | this.ctx = Expression.Parameter (typeof (LuaContext), "ctx"); 110 | this.args = Expression.Parameter (typeof (LuaObject[]), "args"); 111 | this.expression_compiler = new ExpressionCompiler (IL, this.ctx, this.args); 112 | } 113 | 114 | public CompilerExecutor (LuaContext ctx, string [] argNames) 115 | : this (ctx) 116 | { 117 | if (argNames.Length == 0) 118 | return; 119 | 120 | var done = IL.DefineLabel (); 121 | IL.DeclareLocal (typeof (int)); 122 | 123 | IL.Emit (OpCodes.Ldarg_1); // load args array 124 | IL.Emit (OpCodes.Ldlen); 125 | IL.Emit (OpCodes.Stloc_0); 126 | 127 | for (int i = 0; i < argNames.Length; i++) { 128 | // since we don't know how many args were actually passed in, we have to check on each one 129 | IL.Emit (OpCodes.Ldc_I4, i); 130 | IL.Emit (OpCodes.Ldloc_0); 131 | IL.Emit (OpCodes.Bge, done); 132 | 133 | IL.Emit (OpCodes.Ldarg_0); 134 | IL.Emit (OpCodes.Ldstr, argNames [i]); 135 | IL.Emit (OpCodes.Ldarg_1); 136 | IL.Emit (OpCodes.Ldc_I4, i); 137 | IL.Emit (OpCodes.Ldelem, typeof (LuaObject)); 138 | IL.Emit (OpCodes.Call, LuaContext_SetLocal); 139 | 140 | // also have to define args in scope manually here so prebinding works 141 | CurrentScope.Define (argNames [i]); 142 | } 143 | 144 | IL.MarkLabel (done); 145 | } 146 | 147 | public virtual void PushScope () 148 | { 149 | scopes.Push (new LuaContext (CurrentScope)); 150 | } 151 | 152 | public virtual void PushBlockScope () 153 | { 154 | throw new NotSupportedException (); 155 | } 156 | 157 | public virtual void PushFunctionScope (string[] argNames) 158 | { 159 | throw new NotSupportedException (); 160 | } 161 | 162 | public virtual void PopScope () 163 | { 164 | scopes.Pop (); 165 | } 166 | 167 | public virtual void Constant (LuaObject value) 168 | { 169 | switch (value.Type) { 170 | 171 | case LuaType.@string: 172 | stack.Push (Expression.Call (LuaObject_FromString, Expression.Constant (value.AsString ()))); 173 | break; 174 | 175 | case LuaType.number: 176 | stack.Push (Expression.Call (LuaObject_FromNumber, Expression.Constant (value.AsNumber ()))); 177 | break; 178 | 179 | case LuaType.function: 180 | // FIXME: we're actually creating a variable here.. 181 | var fn = value.AsFunction (); 182 | var name = fn.Method.Name; 183 | CurrentScope.SetLocal (name, fn); 184 | Variable (name); 185 | break; 186 | 187 | default: 188 | throw new NotSupportedException (value.Type.ToString ()); 189 | } 190 | } 191 | 192 | public virtual void Variable (string identifier) 193 | { 194 | stack.Push (Expression.Call (ctx, LuaContext_Get, Expression.Constant (identifier))); 195 | } 196 | 197 | public virtual void Call (int argCount) 198 | { 199 | var args = new Expression [argCount]; 200 | 201 | // pop args 202 | for (int i = argCount - 1; i >= 0; i--) 203 | args [i] = stack.Pop (); 204 | 205 | // push function object 206 | stack.Push (Expression.Call (stack.Pop (), LuaObject_AsFunction)); 207 | 208 | // call function 209 | stack.Push (Expression.Call (stack.Pop (), LuaFunction_Invoke, Expression.NewArrayInit (typeof (LuaObject), args))); 210 | } 211 | 212 | public virtual void TableCreate (int initCount) 213 | { 214 | var items = new Expression [initCount]; 215 | 216 | // load up constructor items 217 | for (var i = 0; i < initCount; i++) { 218 | var value = stack.Pop (); 219 | var key = stack.Pop (); 220 | 221 | items [i] = Expression.New (New_LuaTableItem, key, value); 222 | } 223 | 224 | stack.Push (Expression.Call (LuaObject_NewTable, Expression.NewArrayInit (typeof (LuaTableItem), items))); 225 | } 226 | 227 | public virtual void TableGet () 228 | { 229 | var key = stack.Pop (); 230 | stack.Push (Expression.Call (stack.Pop (), LuaObject_this_get, key)); 231 | } 232 | 233 | public virtual void Concatenate () 234 | { 235 | var val2 = Expression.Call (stack.Pop (), LuaObject_AsString); 236 | var val1 = Expression.Call (stack.Pop (), LuaObject_AsString); 237 | 238 | stack.Push (Expression.Call (LuaObject_FromString, Expression.Call (String_Concat, val1, val2))); 239 | } 240 | 241 | public virtual void Negate () 242 | { 243 | stack.Push (Expression.Call (LuaObject_FromBool, Expression.Not (Expression.Call (stack.Pop (), LuaObject_AsBool)))); 244 | } 245 | 246 | public virtual void Or() 247 | { 248 | var val2 = Expression.Call(stack.Pop(), LuaObject_AsBool); 249 | var val1 = Expression.Call(stack.Pop(), LuaObject_AsBool); 250 | stack.Push(Expression.Call(LuaObject_FromBool, Expression.OrElse(val1, val2))); 251 | } 252 | 253 | public virtual void And() 254 | { 255 | var val2 = Expression.Call(stack.Pop(), LuaObject_AsBool); 256 | var val1 = Expression.Call(stack.Pop(), LuaObject_AsBool); 257 | stack.Push(Expression.Call(LuaObject_FromBool, Expression.AndAlso(val1, val2))); 258 | } 259 | 260 | public virtual void Equal() 261 | { 262 | var val2 = stack.Pop(); 263 | var val1 = stack.Pop(); 264 | stack.Push(Expression.Call(LuaObject_FromBool, Expression.Call(val1, LuaObject_Equals, val2))); 265 | } 266 | 267 | public virtual void NotEqual() 268 | { 269 | var val2 = stack.Pop(); 270 | var val1 = stack.Pop(); 271 | stack.Push(Expression.Call(LuaObject_FromBool, Expression.Not(Expression.Call(val1, LuaObject_Equals, val2)))); 272 | } 273 | #if NET35 274 | public virtual void IfThenElse() 275 | { 276 | throw new NotImplementedException(); 277 | } 278 | #else 279 | public virtual void IfThenElse() 280 | { 281 | var Else = Expression.Call(stack.Pop(), LuaObject_AsFunction); 282 | var Then = Expression.Call(stack.Pop(), LuaObject_AsFunction); 283 | var Cond = Expression.Call(stack.Pop(), LuaObject_AsBool); 284 | stack.Push(Expression.IfThenElse( 285 | Cond, 286 | Expression.Call(Then, LuaFunction_Invoke, Expression.NewArrayInit(typeof(LuaObject), new Expression[]{})), 287 | Expression.Call(Else, LuaFunction_Invoke, Expression.NewArrayInit(typeof(LuaObject), new Expression[]{})) 288 | )); 289 | } 290 | #endif 291 | 292 | 293 | public virtual void Greater() 294 | { 295 | var val2 = Expression.Call(stack.Pop(), LuaObject_AsNumber); 296 | var val1 = Expression.Call(stack.Pop(), LuaObject_AsNumber); 297 | 298 | stack.Push(Expression.Call (LuaObject_FromBool, Expression.GreaterThan(val1, val2))); 299 | } 300 | public virtual void Smaller() 301 | { 302 | var val2 = Expression.Call(stack.Pop(), LuaObject_AsNumber); 303 | var val1 = Expression.Call(stack.Pop(), LuaObject_AsNumber); 304 | 305 | stack.Push(Expression.Call(LuaObject_FromBool, Expression.LessThan(val1, val2))); 306 | } 307 | public virtual void GreaterOrEqual() 308 | { 309 | var val2 = Expression.Call(stack.Pop(), LuaObject_AsNumber); 310 | var val1 = Expression.Call(stack.Pop(), LuaObject_AsNumber); 311 | 312 | stack.Push(Expression.Call(LuaObject_FromBool, Expression.GreaterThanOrEqual(val1, val2))); 313 | } 314 | public virtual void SmallerOrEqual() 315 | { 316 | var val2 = Expression.Call(stack.Pop(), LuaObject_AsNumber); 317 | var val1 = Expression.Call(stack.Pop(), LuaObject_AsNumber); 318 | 319 | stack.Push(Expression.Call(LuaObject_FromBool, Expression.LessThanOrEqual(val1, val2))); 320 | } 321 | 322 | public virtual void Add () 323 | { 324 | var val2 = Expression.Call (stack.Pop (), LuaObject_AsNumber); 325 | var val1 = Expression.Call (stack.Pop (), LuaObject_AsNumber); 326 | 327 | stack.Push (Expression.Call (LuaObject_FromNumber, Expression.Add (val1, val2))); 328 | } 329 | 330 | public virtual void Subtract () 331 | { 332 | var val2 = Expression.Call (stack.Pop (), LuaObject_AsNumber); 333 | var val1 = Expression.Call (stack.Pop (), LuaObject_AsNumber); 334 | 335 | stack.Push (Expression.Call (LuaObject_FromNumber, Expression.Subtract (val1, val2))); 336 | } 337 | 338 | public virtual void Multiply () 339 | { 340 | var val2 = Expression.Call (stack.Pop (), LuaObject_AsNumber); 341 | var val1 = Expression.Call (stack.Pop (), LuaObject_AsNumber); 342 | 343 | stack.Push (Expression.Call (LuaObject_FromNumber, Expression.Multiply (val1, val2))); 344 | } 345 | 346 | public virtual void Divide () 347 | { 348 | var val2 = Expression.Call (stack.Pop (), LuaObject_AsNumber); 349 | var val1 = Expression.Call (stack.Pop (), LuaObject_AsNumber); 350 | 351 | stack.Push (Expression.Call (LuaObject_FromNumber, Expression.Divide (val1, val2))); 352 | } 353 | 354 | public virtual void PopStack () 355 | { 356 | // turn last expression into a statement 357 | expression_compiler.Compile (stack.Pop ()); 358 | IL.Emit (OpCodes.Pop); 359 | } 360 | 361 | public virtual void Assign (string identifier, bool localScope) 362 | { 363 | CurrentScope.Define (identifier); 364 | 365 | IL.Emit (OpCodes.Ldarg_0); 366 | IL.Emit (OpCodes.Ldstr, identifier); 367 | expression_compiler.Compile (stack.Pop ()); 368 | 369 | if (localScope) 370 | IL.Emit (OpCodes.Call, LuaContext_SetLocal); 371 | 372 | else 373 | IL.Emit (OpCodes.Call, LuaContext_SetGlobal); 374 | } 375 | 376 | public virtual void TableSet () 377 | { 378 | var val = stack.Pop (); 379 | var key = stack.Pop (); 380 | 381 | expression_compiler.Compile (Expression.Call (stack.Pop (), LuaObject_this_set, key, val)); 382 | } 383 | 384 | public virtual void Return () 385 | { 386 | if (stack.Count == 0) { 387 | IL.Emit (OpCodes.Ldsfld, LuaObject_Nil); 388 | 389 | } else if (stack.Count == 1) { 390 | expression_compiler.Compile (stack.Pop ()); 391 | 392 | } else { 393 | 394 | throw new Exception ("stack height is greater than one!"); 395 | } 396 | IL.Emit (OpCodes.Ret); 397 | } 398 | 399 | public virtual LuaObject Result () 400 | { 401 | return Compile () (new LuaObject [0]); 402 | } 403 | 404 | public void ColonOperator() 405 | { 406 | var key = stack.Pop(); 407 | var table = stack.Pop(); 408 | stack.Push(Expression.Call(table, LuaObject_this_get, key)); 409 | stack.Push(table); 410 | } 411 | 412 | public LuaFunction Compile () 413 | { 414 | if (compiled != null) 415 | return compiled; 416 | 417 | Return (); 418 | 419 | #if DEBUG_WRITE_IL 420 | typ.CreateType (); 421 | asm.Save ("Debug_IL_Output.dll"); 422 | Environment.Exit (0); 423 | return null; 424 | #else 425 | compiled = (LuaFunction)method.CreateDelegate (typeof (LuaFunction), CurrentScope); 426 | return compiled; 427 | #endif 428 | } 429 | } 430 | } -------------------------------------------------------------------------------- /src/Executors/DefaultExecutor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | DefaultExecutor.cs: Default execution policy 3 | 4 | Copyright (c) 2011 Alexander Corrado 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace AluminumLua.Executors { 29 | 30 | public class DefaultExecutor : IExecutor { 31 | 32 | protected Stack executors; 33 | public IExecutor Target { get { return executors.Peek (); } } 34 | public LuaContext CurrentScope { get { return Target.CurrentScope; } } 35 | 36 | public DefaultExecutor (LuaContext ctx) 37 | { 38 | var defaultExecutor = new InterpreterExecutor (ctx); 39 | 40 | this.executors = new Stack (); 41 | this.executors.Push (defaultExecutor); 42 | } 43 | 44 | protected DefaultExecutor () 45 | { 46 | } 47 | 48 | // ---- 49 | 50 | // scoping: 51 | public virtual void PushScope () 52 | { 53 | var current = Target; 54 | current.PushScope (); 55 | executors.Push (current); 56 | } 57 | 58 | public virtual void PushBlockScope () 59 | { 60 | executors.Push (new CompilerExecutor (new LuaContext (CurrentScope))); 61 | } 62 | 63 | public virtual void PushFunctionScope (string [] argNames) 64 | { 65 | executors.Push (new CompilerExecutor (new LuaContext (CurrentScope), argNames)); 66 | } 67 | 68 | public virtual void PopScope () 69 | { 70 | var old = executors.Pop (); 71 | var fn = old as CompilerExecutor; 72 | 73 | if (fn != null) 74 | Target.Constant (LuaObject.FromFunction (fn.Compile ())); 75 | 76 | old.PopScope (); 77 | } 78 | 79 | // expressions: 80 | public virtual void Constant (LuaObject value) 81 | { 82 | Target.Constant (value); 83 | } 84 | 85 | public virtual void Variable (string identifier) 86 | { 87 | Target.Variable (identifier); 88 | } 89 | 90 | public virtual void Call (int argCount) 91 | { 92 | Target.Call (argCount); 93 | } 94 | 95 | public virtual void TableCreate (int initCount) 96 | { 97 | Target.TableCreate (initCount); 98 | } 99 | 100 | public virtual void TableGet () 101 | { 102 | Target.TableGet (); 103 | } 104 | 105 | public virtual void Concatenate () 106 | { 107 | Target.Concatenate (); 108 | } 109 | 110 | public virtual void Negate () 111 | { 112 | Target.Negate (); 113 | } 114 | 115 | public virtual void And() 116 | { 117 | Target.And(); 118 | } 119 | public virtual void Or() 120 | { 121 | Target.Or(); 122 | } 123 | public virtual void Equal() 124 | { 125 | Target.Equal(); 126 | } 127 | public virtual void NotEqual() 128 | { 129 | Target.NotEqual(); 130 | } 131 | 132 | public virtual void IfThenElse() 133 | { 134 | Target.IfThenElse(); 135 | } 136 | 137 | public virtual void Greater() 138 | { 139 | Target.Greater(); 140 | } 141 | public virtual void Smaller() 142 | { 143 | Target.Smaller(); 144 | } 145 | public virtual void GreaterOrEqual() 146 | { 147 | Target.GreaterOrEqual(); 148 | } 149 | public virtual void SmallerOrEqual() 150 | { 151 | Target.SmallerOrEqual(); 152 | } 153 | 154 | public virtual void Add () 155 | { 156 | Target.Add (); 157 | } 158 | 159 | public virtual void Subtract () 160 | { 161 | Target.Subtract (); 162 | } 163 | 164 | public virtual void Multiply () 165 | { 166 | Target.Multiply (); 167 | } 168 | 169 | public virtual void Divide () 170 | { 171 | Target.Divide (); 172 | } 173 | 174 | public virtual void PopStack () 175 | { 176 | Target.PopStack (); 177 | } 178 | 179 | // statements: 180 | public virtual void Assign (string identifier, bool localScope) 181 | { 182 | Target.Assign (identifier, localScope); 183 | } 184 | 185 | public virtual void TableSet () 186 | { 187 | Target.TableSet (); 188 | } 189 | 190 | public virtual void Return () 191 | { 192 | Target.Return (); 193 | } 194 | 195 | public void ColonOperator() 196 | { 197 | Target.ColonOperator(); 198 | } 199 | 200 | public virtual LuaObject Result () 201 | { 202 | return Target.Result (); 203 | } 204 | 205 | 206 | } 207 | } 208 | 209 | -------------------------------------------------------------------------------- /src/Executors/ExpressionTrees/ExpressionCompiler.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ExpressionCompiler.cs: A really simple .NET 3.5 partial expression tree compiler 3 | 4 | Copyright (c) 2011 Alexander Corrado 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | using System.Linq; 28 | using System.Reflection; 29 | using System.Reflection.Emit; 30 | using System.Linq.Expressions; 31 | 32 | namespace AluminumLua.Executors.ExpressionTrees { 33 | 34 | public class ExpressionCompiler : ExpressionVisitor { 35 | 36 | private static readonly MethodInfo Type_GetTypeFromHandle = typeof (Type).GetMethod ("GetTypeFromHandle", BindingFlags.Public | BindingFlags.Static); 37 | private static readonly MethodInfo MethodBase_GetMethodFromHandle = typeof (MethodBase).GetMethod ("GetMethodFromHandle", new Type [] { typeof (RuntimeMethodHandle) }); 38 | 39 | protected ILGenerator IL; 40 | protected string [] arg_names; 41 | protected Dictionary registers; 42 | 43 | public ExpressionCompiler (ILGenerator target, params ParameterExpression [] args) 44 | { 45 | this.IL = target; 46 | this.arg_names = args.Select (p => p.Name).ToArray (); 47 | this.registers = new Dictionary (); 48 | } 49 | 50 | public void Compile (Expression expression) 51 | { 52 | Visit (expression); 53 | } 54 | 55 | protected LocalBuilder LockRegister (Type type) 56 | { 57 | LocalBuilder reg; 58 | if (registers.TryGetValue (type, out reg)) 59 | registers.Remove (type); 60 | else 61 | reg = IL.DeclareLocal (type); 62 | return reg; 63 | } 64 | 65 | protected void UnlockRegister (LocalBuilder reg) 66 | { 67 | if (registers.ContainsKey (reg.LocalType)) 68 | return; 69 | 70 | registers.Add (reg.LocalType, reg); 71 | } 72 | 73 | protected override void VisitConstant (ConstantExpression c) 74 | { 75 | if (c.Value == null) 76 | IL.Emit (OpCodes.Ldnull); 77 | 78 | else if (c.Value is string) 79 | IL.Emit (OpCodes.Ldstr, (string)c.Value); 80 | 81 | else if (c.Value is int) 82 | IL.Emit (OpCodes.Ldc_I4, (int)c.Value); 83 | 84 | else if (c.Value is double) 85 | IL.Emit (OpCodes.Ldc_R8, (double)c.Value); 86 | 87 | else if (c.Value is Type) { 88 | IL.Emit (OpCodes.Ldtoken, (Type)c.Value); 89 | IL.Emit (OpCodes.Call, Type_GetTypeFromHandle); 90 | 91 | } else if (c.Value is MethodInfo) { 92 | IL.Emit (OpCodes.Ldtoken, (MethodInfo)c.Value); 93 | IL.Emit (OpCodes.Call, MethodBase_GetMethodFromHandle); 94 | IL.Emit (OpCodes.Castclass, typeof (MethodInfo)); 95 | 96 | } else 97 | throw new NotSupportedException (c.Value.GetType ().FullName); 98 | } 99 | 100 | protected override void VisitParameter (ParameterExpression p) 101 | { 102 | IL.Emit (OpCodes.Ldarg, Array.IndexOf (arg_names, p.Name)); 103 | } 104 | 105 | protected override void VisitUnary(UnaryExpression u) 106 | { 107 | Visit(u.Operand); 108 | switch (u.NodeType) 109 | { 110 | case ExpressionType.Not: 111 | IL.Emit(OpCodes.Not); 112 | break; 113 | } 114 | } 115 | 116 | protected override void VisitBinary (BinaryExpression b) 117 | { 118 | Visit (b.Left); 119 | 120 | switch (b.NodeType) { 121 | 122 | case ExpressionType.Add: 123 | Visit(b.Right); 124 | IL.Emit (OpCodes.Add); 125 | break; 126 | 127 | case ExpressionType.Subtract: 128 | Visit(b.Right); 129 | IL.Emit (OpCodes.Sub); 130 | break; 131 | 132 | case ExpressionType.Multiply: 133 | Visit(b.Right); 134 | IL.Emit (OpCodes.Mul); 135 | break; 136 | 137 | case ExpressionType.Divide: 138 | Visit(b.Right); 139 | IL.Emit (OpCodes.Div); 140 | break; 141 | case ExpressionType.GreaterThan: 142 | Visit(b.Right); 143 | IL.Emit(OpCodes.Cgt); 144 | break; 145 | case ExpressionType.GreaterThanOrEqual: 146 | Visit(b.Right); 147 | IL.Emit(OpCodes.Clt); 148 | IL.Emit(OpCodes.Not); 149 | break; 150 | case ExpressionType.LessThan: 151 | Visit(b.Right); 152 | IL.Emit(OpCodes.Clt); 153 | break; 154 | case ExpressionType.LessThanOrEqual: 155 | Visit(b.Right); 156 | IL.Emit(OpCodes.Cgt); 157 | IL.Emit(OpCodes.Not); 158 | break; 159 | case ExpressionType.AndAlso: 160 | var ItsFalse = IL.DefineLabel(); 161 | var EndAnd = IL.DefineLabel(); 162 | IL.Emit(OpCodes.Brfalse, ItsFalse); 163 | Visit(b.Right); 164 | IL.Emit(OpCodes.Br, EndAnd); 165 | IL.MarkLabel(ItsFalse); 166 | IL.Emit(OpCodes.Ldc_I4_0); 167 | IL.MarkLabel(EndAnd); 168 | break; 169 | case ExpressionType.OrElse: 170 | var ItsTrue = IL.DefineLabel(); 171 | var EndOr = IL.DefineLabel(); 172 | IL.Emit(OpCodes.Brtrue, ItsTrue); 173 | Visit(b.Right); 174 | IL.Emit(OpCodes.Br, EndOr); 175 | IL.MarkLabel(ItsTrue); 176 | IL.Emit(OpCodes.Ldc_I4_1); 177 | IL.MarkLabel(EndOr); 178 | break; 179 | case ExpressionType.Equal: 180 | Visit(b.Right); 181 | IL.Emit(OpCodes.Ceq); 182 | break; 183 | case ExpressionType.NotEqual: 184 | Visit(b.Right); 185 | IL.Emit(OpCodes.Ceq); 186 | IL.Emit(OpCodes.Not); 187 | break; 188 | default: 189 | throw new NotImplementedException (b.Type.ToString ()); 190 | } 191 | } 192 | 193 | protected override void VisitMethodCall (MethodCallExpression m) 194 | { 195 | LocalBuilder reg = null; 196 | 197 | if (m.Object != null) { 198 | Visit (m.Object); 199 | 200 | if (m.Object.Type.IsValueType) { 201 | // for the record, I hate that this is necessary 202 | reg = LockRegister (m.Object.Type); 203 | IL.Emit (OpCodes.Stloc, reg); 204 | IL.Emit (OpCodes.Ldloca, reg); 205 | } 206 | } 207 | 208 | foreach (var arg in m.Arguments) 209 | Visit (arg); 210 | 211 | // FIXME: AlumninumLua never calls virtual methods while executing a script.. does it? 212 | IL.Emit (OpCodes.Call, m.Method); 213 | 214 | if (reg != null) 215 | UnlockRegister (reg); 216 | } 217 | 218 | protected override void VisitNew (NewExpression nex) 219 | { 220 | foreach (var arg in nex.Arguments) 221 | Visit (arg); 222 | 223 | IL.Emit (OpCodes.Newobj, nex.Constructor); 224 | } 225 | 226 | protected override void VisitNewArray (NewArrayExpression na) 227 | { 228 | IL.Emit (OpCodes.Ldc_I4, na.Expressions.Count); 229 | IL.Emit (OpCodes.Newarr, na.Type.GetElementType ()); 230 | 231 | int i = 0; 232 | foreach (var item in na.Expressions) { 233 | IL.Emit (OpCodes.Dup); // keep the array on the stack 234 | IL.Emit (OpCodes.Ldc_I4, i++); 235 | Visit (item); 236 | IL.Emit (OpCodes.Stelem, item.Type); 237 | } 238 | } 239 | 240 | protected override void VisitConditional(ConditionalExpression c) 241 | { 242 | var End = IL.DefineLabel(); 243 | var IfFalse = IL.DefineLabel(); 244 | Visit(c.Test); 245 | 246 | IL.Emit(OpCodes.Brfalse, IfFalse); 247 | Visit(c.IfTrue); 248 | IL.Emit(OpCodes.Br, End); 249 | IL.MarkLabel(IfFalse); 250 | Visit(c.IfFalse); 251 | IL.MarkLabel(End); 252 | } 253 | } 254 | } 255 | 256 | -------------------------------------------------------------------------------- /src/Executors/ExpressionTrees/ExpressionVisitor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * ExpressionVisitor.cs 3 | * Based on: http://msdn.microsoft.com/en-us/library/bb882521%28v=VS.90%29.aspx 4 | */ 5 | 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Collections.ObjectModel; 9 | using System.Linq.Expressions; 10 | 11 | namespace AluminumLua.Executors.ExpressionTrees { 12 | 13 | public abstract class ExpressionVisitor { 14 | 15 | protected ExpressionVisitor() 16 | { 17 | } 18 | 19 | protected virtual void Visit(Expression exp) 20 | { 21 | if (exp == null) 22 | return; 23 | switch (exp.NodeType) 24 | { 25 | case ExpressionType.Negate: 26 | case ExpressionType.NegateChecked: 27 | case ExpressionType.Not: 28 | case ExpressionType.Convert: 29 | case ExpressionType.ConvertChecked: 30 | case ExpressionType.ArrayLength: 31 | case ExpressionType.Quote: 32 | case ExpressionType.TypeAs: 33 | this.VisitUnary((UnaryExpression)exp); 34 | break; 35 | case ExpressionType.Add: 36 | case ExpressionType.AddChecked: 37 | case ExpressionType.Subtract: 38 | case ExpressionType.SubtractChecked: 39 | case ExpressionType.Multiply: 40 | case ExpressionType.MultiplyChecked: 41 | case ExpressionType.Divide: 42 | case ExpressionType.Modulo: 43 | case ExpressionType.And: 44 | case ExpressionType.AndAlso: 45 | case ExpressionType.Or: 46 | case ExpressionType.OrElse: 47 | case ExpressionType.LessThan: 48 | case ExpressionType.LessThanOrEqual: 49 | case ExpressionType.GreaterThan: 50 | case ExpressionType.GreaterThanOrEqual: 51 | case ExpressionType.Equal: 52 | case ExpressionType.NotEqual: 53 | case ExpressionType.Coalesce: 54 | case ExpressionType.ArrayIndex: 55 | case ExpressionType.RightShift: 56 | case ExpressionType.LeftShift: 57 | case ExpressionType.ExclusiveOr: 58 | this.VisitBinary((BinaryExpression)exp); 59 | break; 60 | case ExpressionType.TypeIs: 61 | this.VisitTypeIs((TypeBinaryExpression)exp); 62 | break; 63 | case ExpressionType.Conditional: 64 | this.VisitConditional((ConditionalExpression)exp); 65 | break; 66 | case ExpressionType.Constant: 67 | this.VisitConstant((ConstantExpression)exp); 68 | break; 69 | case ExpressionType.Parameter: 70 | this.VisitParameter((ParameterExpression)exp); 71 | break; 72 | case ExpressionType.MemberAccess: 73 | this.VisitMemberAccess((MemberExpression)exp); 74 | break; 75 | case ExpressionType.Call: 76 | this.VisitMethodCall((MethodCallExpression)exp); 77 | break; 78 | case ExpressionType.Lambda: 79 | this.VisitLambda((LambdaExpression)exp); 80 | break; 81 | case ExpressionType.New: 82 | this.VisitNew((NewExpression)exp); 83 | break; 84 | case ExpressionType.NewArrayInit: 85 | case ExpressionType.NewArrayBounds: 86 | this.VisitNewArray((NewArrayExpression)exp); 87 | break; 88 | case ExpressionType.Invoke: 89 | this.VisitInvocation((InvocationExpression)exp); 90 | break; 91 | case ExpressionType.MemberInit: 92 | this.VisitMemberInit((MemberInitExpression)exp); 93 | break; 94 | case ExpressionType.ListInit: 95 | this.VisitListInit((ListInitExpression)exp); 96 | break; 97 | default: 98 | throw new Exception(string.Format("Unhandled expression type: '{0}'", exp.NodeType)); 99 | } 100 | } 101 | 102 | protected virtual void VisitBinding(MemberBinding binding) 103 | { 104 | switch (binding.BindingType) 105 | { 106 | case MemberBindingType.Assignment: 107 | this.VisitMemberAssignment((MemberAssignment)binding); 108 | break; 109 | case MemberBindingType.MemberBinding: 110 | this.VisitMemberMemberBinding((MemberMemberBinding)binding); 111 | break; 112 | case MemberBindingType.ListBinding: 113 | this.VisitMemberListBinding((MemberListBinding)binding); 114 | break; 115 | default: 116 | throw new Exception(string.Format("Unhandled binding type '{0}'", binding.BindingType)); 117 | } 118 | throw new NotImplementedException (); 119 | } 120 | 121 | protected virtual void VisitElementInitializer(ElementInit initializer) 122 | { 123 | this.VisitExpressionList(initializer.Arguments); 124 | throw new NotImplementedException (); 125 | } 126 | 127 | protected virtual void VisitUnary(UnaryExpression u) 128 | { 129 | this.Visit(u.Operand); 130 | throw new NotImplementedException (); 131 | } 132 | 133 | protected virtual void VisitBinary(BinaryExpression b) 134 | { 135 | this.Visit(b.Left); 136 | this.Visit(b.Right); 137 | this.Visit(b.Conversion); 138 | throw new NotImplementedException (); 139 | } 140 | 141 | protected virtual void VisitTypeIs(TypeBinaryExpression b) 142 | { 143 | this.Visit(b.Expression); 144 | throw new NotImplementedException (); 145 | } 146 | 147 | protected virtual void VisitConstant(ConstantExpression c) 148 | { 149 | throw new NotImplementedException (); 150 | } 151 | 152 | protected virtual void VisitConditional(ConditionalExpression c) 153 | { 154 | this.Visit(c.Test); 155 | 156 | this.Visit(c.IfTrue); 157 | this.Visit(c.IfFalse); 158 | throw new NotImplementedException (); 159 | } 160 | 161 | protected virtual void VisitParameter(ParameterExpression p) 162 | { 163 | throw new NotImplementedException (); 164 | } 165 | 166 | protected virtual void VisitMemberAccess(MemberExpression m) 167 | { 168 | this.Visit(m.Expression); 169 | throw new NotImplementedException (); 170 | } 171 | 172 | protected virtual void VisitMethodCall(MethodCallExpression m) 173 | { 174 | this.Visit(m.Object); 175 | this.VisitExpressionList(m.Arguments); 176 | throw new NotImplementedException (); 177 | } 178 | 179 | protected virtual void VisitExpressionList(ReadOnlyCollection original) 180 | { 181 | for (int i = 0, n = original.Count; i < n; i++) 182 | this.Visit(original[i]); 183 | 184 | throw new NotImplementedException (); 185 | } 186 | 187 | protected virtual void VisitMemberAssignment(MemberAssignment assignment) 188 | { 189 | this.Visit(assignment.Expression); 190 | throw new NotImplementedException (); 191 | } 192 | 193 | protected virtual void VisitMemberMemberBinding(MemberMemberBinding binding) 194 | { 195 | this.VisitBindingList(binding.Bindings); 196 | throw new NotImplementedException (); 197 | } 198 | 199 | protected virtual void VisitMemberListBinding(MemberListBinding binding) 200 | { 201 | this.VisitElementInitializerList(binding.Initializers); 202 | throw new NotImplementedException (); 203 | } 204 | 205 | protected virtual void VisitBindingList(ReadOnlyCollection original) 206 | { 207 | for (int i = 0, n = original.Count; i < n; i++) 208 | this.VisitBinding(original[i]); 209 | 210 | throw new NotImplementedException (); 211 | } 212 | 213 | protected virtual void VisitElementInitializerList(ReadOnlyCollection original) 214 | { 215 | for (int i = 0, n = original.Count; i < n; i++) 216 | this.VisitElementInitializer(original[i]); 217 | 218 | throw new NotImplementedException (); 219 | } 220 | 221 | protected virtual void VisitLambda(LambdaExpression lambda) 222 | { 223 | this.Visit(lambda.Body); 224 | throw new NotImplementedException (); 225 | } 226 | 227 | protected virtual void VisitNew(NewExpression nex) 228 | { 229 | this.VisitExpressionList(nex.Arguments); 230 | throw new NotImplementedException (); 231 | } 232 | 233 | protected virtual void VisitMemberInit(MemberInitExpression init) 234 | { 235 | this.VisitNew(init.NewExpression); 236 | this.VisitBindingList(init.Bindings); 237 | throw new NotImplementedException (); 238 | } 239 | 240 | protected virtual void VisitListInit(ListInitExpression init) 241 | { 242 | this.VisitNew(init.NewExpression); 243 | this.VisitElementInitializerList(init.Initializers); 244 | throw new NotImplementedException (); 245 | } 246 | 247 | protected virtual void VisitNewArray(NewArrayExpression na) 248 | { 249 | this.VisitExpressionList(na.Expressions); 250 | throw new NotImplementedException (); 251 | } 252 | 253 | protected virtual void VisitInvocation(InvocationExpression iv) 254 | { 255 | this.VisitExpressionList(iv.Arguments); 256 | this.Visit(iv.Expression); 257 | throw new NotImplementedException (); 258 | } 259 | } 260 | } 261 | -------------------------------------------------------------------------------- /src/Executors/IExecutor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | IExecutor.cs: Decouples execution from parsing 3 | 4 | Copyright (c) 2011 Alexander Corrado 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace AluminumLua.Executors { 29 | 30 | using LuaTable = IDictionary; 31 | 32 | // All IExecutor implementations should have a constructor that takes a LuaContext 33 | public interface IExecutor { 34 | 35 | // scoping: 36 | void PushScope (); 37 | void PushBlockScope (); // a block of code that may be repeated (ex. loop body) 38 | void PushFunctionScope (string [] argNames); 39 | LuaContext CurrentScope { get; } 40 | void PopScope (); // if it was a function or block scope, function object is left on stack 41 | 42 | 43 | // expressions: 44 | void Constant (LuaObject value); // pushes value 45 | void Variable (string identifier); // pushes value 46 | void Call (int argCount); // pops arg * argCount, pops function; pushes return value 47 | void TableCreate (int initCount); // pops (value, key) * initCount; pushes table 48 | void TableGet (); // pops key, pops table, pushes value 49 | 50 | void Concatenate (); // pops , pops ; pushes 51 | void Negate (); // pops value; pushes negated value (boolean) 52 | void And (); // pops , pops ; pushes && (bool) 53 | void Or (); // pops , pops ; pushes || (bool) 54 | void Equal (); // pops , pops ; pushes == (bool) 55 | void NotEqual (); // pops , pops ; pushes != (bool) 56 | void IfThenElse (); // pops , pops , pops ; pushes ? : (function) 57 | 58 | void Greater (); // pops , pops ; pushes > (bool) 59 | void Smaller (); // pops , pops ; pushes < (bool) 60 | void GreaterOrEqual (); // pops , pops ; pushes >= (bool) 61 | void SmallerOrEqual (); // pops , pops ; pushes <= (bool) 62 | 63 | void Add (); // pops , pops ; pushes + (numeric) 64 | void Subtract (); // pops , pops ; pushes - (numeric) 65 | void Multiply (); // pops , pops ; pushes * (numeric) 66 | void Divide (); // pops , pops ; pushes / (numeric) 67 | 68 | // statements: 69 | void PopStack (); // pops and discards value 70 | void Assign (string identifier, bool localScope); // pops a value 71 | void TableSet (); // pops value, pops key, pops table, sets table.key = value 72 | void Return (); // pops a value 73 | 74 | void ColonOperator(); 75 | 76 | // to execute: (some IExecutors - like InterpreterExecutor - may have executed instructions as they came in) 77 | LuaObject Result (); 78 | } 79 | } 80 | 81 | -------------------------------------------------------------------------------- /src/Executors/InterpreterExecutor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | InterpreterExecutor.cs: Immediately executes the code by interpreting it 3 | 4 | Copyright (c) 2011 Alexander Corrado 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace AluminumLua.Executors { 29 | 30 | public class InterpreterExecutor : IExecutor { 31 | 32 | protected Stack scopes; 33 | protected Stack stack; 34 | 35 | public LuaContext CurrentScope { get { return scopes.Peek (); } } 36 | 37 | public InterpreterExecutor (LuaContext ctx) 38 | { 39 | this.scopes = new Stack (); 40 | this.scopes.Push (ctx); 41 | 42 | this.stack = new Stack (); 43 | } 44 | 45 | public virtual void PushScope () 46 | { 47 | scopes.Push (new LuaContext (CurrentScope)); 48 | } 49 | 50 | public virtual void PushBlockScope () 51 | { 52 | throw new NotSupportedException (); 53 | } 54 | 55 | public virtual void PushFunctionScope (string [] argNames) 56 | { 57 | throw new NotSupportedException (); 58 | } 59 | 60 | public virtual void PopScope () 61 | { 62 | scopes.Pop (); 63 | } 64 | 65 | public virtual void Constant (LuaObject value) 66 | { 67 | stack.Push (value); 68 | } 69 | 70 | public virtual void Variable (string identifier) 71 | { 72 | stack.Push (CurrentScope.Get (identifier)); 73 | } 74 | 75 | public virtual void Call (int argCount) 76 | { 77 | var args = new LuaObject [argCount]; 78 | 79 | for (var i = argCount - 1; i >= 0; i--) 80 | args [i] = stack.Pop (); 81 | 82 | stack.Push (stack.Pop ().AsFunction () (args)); 83 | } 84 | 85 | public virtual void TableCreate (int initCount) 86 | { 87 | var table = LuaObject.NewTable (); 88 | 89 | for (var i = 0; i < initCount; i++) { 90 | var value = stack.Pop (); 91 | var key = stack.Pop (); 92 | 93 | table [key] = value; 94 | } 95 | 96 | stack.Push (table); 97 | } 98 | 99 | public virtual void TableGet () 100 | { 101 | var key = stack.Pop (); 102 | var table = stack.Pop (); 103 | stack.Push (table [key]); 104 | } 105 | 106 | public virtual void Concatenate () 107 | { 108 | var val2 = stack.Pop ().AsString (); 109 | var val1 = stack.Pop ().AsString (); 110 | 111 | stack.Push (LuaObject.FromString (string.Concat (val1, val2))); 112 | } 113 | 114 | public virtual void Negate () 115 | { 116 | var val = stack.Pop ().AsBool (); 117 | stack.Push (LuaObject.FromBool (!val)); 118 | } 119 | 120 | public virtual void Or() 121 | { 122 | var val2 = stack.Pop().AsBool(); 123 | var val1 = stack.Pop().AsBool(); 124 | stack.Push(LuaObject.FromBool(val1 || val2)); 125 | } 126 | 127 | public virtual void And() 128 | { 129 | var val2 = stack.Pop().AsBool(); 130 | var val1 = stack.Pop().AsBool(); 131 | stack.Push(LuaObject.FromBool(val1 && val2)); 132 | } 133 | 134 | public virtual void Equal() 135 | { 136 | var val2 = stack.Pop(); 137 | var val1 = stack.Pop(); 138 | stack.Push(LuaObject.FromBool(val1.Equals(val2))); 139 | } 140 | 141 | public virtual void NotEqual() 142 | { 143 | var val2 = stack.Pop(); 144 | var val1 = stack.Pop(); 145 | stack.Push(LuaObject.FromBool(!val1.Equals(val2))); 146 | } 147 | 148 | public virtual void IfThenElse() 149 | { 150 | var Else = stack.Pop().AsFunction(); 151 | var Then = stack.Pop().AsFunction(); 152 | var Cond = stack.Pop().AsBool(); 153 | if (Cond) Then.Invoke(new LuaObject[] { }); else Else.Invoke(new LuaObject[] { }); 154 | } 155 | 156 | public virtual void Greater() 157 | { 158 | var val2 = stack.Pop().AsNumber(); 159 | var val1 = stack.Pop().AsNumber(); 160 | 161 | stack.Push(LuaObject.FromBool(val1 > val2)); 162 | } 163 | public virtual void Smaller() 164 | { 165 | var val2 = stack.Pop().AsNumber(); 166 | var val1 = stack.Pop().AsNumber(); 167 | 168 | stack.Push(LuaObject.FromBool(val1 < val2)); 169 | } 170 | public virtual void GreaterOrEqual() 171 | { 172 | var val2 = stack.Pop().AsNumber(); 173 | var val1 = stack.Pop().AsNumber(); 174 | 175 | stack.Push(LuaObject.FromBool(val1 >= val2)); 176 | } 177 | public virtual void SmallerOrEqual() 178 | { 179 | var val2 = stack.Pop().AsNumber(); 180 | var val1 = stack.Pop().AsNumber(); 181 | 182 | stack.Push(LuaObject.FromBool(val1 <= val2)); 183 | } 184 | 185 | public virtual void Add () 186 | { 187 | var val2 = stack.Pop ().AsNumber (); 188 | var val1 = stack.Pop ().AsNumber (); 189 | 190 | stack.Push (LuaObject.FromNumber (val1 + val2)); 191 | } 192 | 193 | public virtual void Subtract () 194 | { 195 | var val2 = stack.Pop ().AsNumber (); 196 | var val1 = stack.Pop ().AsNumber (); 197 | 198 | stack.Push (LuaObject.FromNumber (val1 - val2)); 199 | } 200 | 201 | public virtual void Multiply () 202 | { 203 | var val2 = stack.Pop ().AsNumber (); 204 | var val1 = stack.Pop ().AsNumber (); 205 | 206 | stack.Push (LuaObject.FromNumber (val1 * val2)); 207 | } 208 | 209 | public virtual void Divide () 210 | { 211 | var val2 = stack.Pop ().AsNumber (); 212 | var val1 = stack.Pop ().AsNumber (); 213 | 214 | stack.Push (LuaObject.FromNumber (val1 / val2)); 215 | } 216 | 217 | public virtual void PopStack () 218 | { 219 | stack.Pop (); 220 | } 221 | 222 | public virtual void Assign (string identifier, bool localScope) 223 | { 224 | if (localScope) 225 | CurrentScope.SetLocal (identifier, stack.Pop ()); 226 | else 227 | CurrentScope.SetGlobal (identifier, stack.Pop ()); 228 | } 229 | 230 | public virtual void TableSet () 231 | { 232 | var value = stack.Pop (); 233 | var key = stack.Pop (); 234 | var table = stack.Pop (); 235 | 236 | table [key] = value; 237 | } 238 | 239 | public virtual void Return () 240 | { 241 | // FIXME: This will do something once the interpreter can support uncompiled functions /: 242 | } 243 | 244 | public virtual LuaObject Result () 245 | { 246 | if (stack.Count > 0) 247 | return stack.Pop (); 248 | 249 | return LuaObject.Nil; 250 | } 251 | 252 | public void ColonOperator() 253 | { 254 | var key = stack.Pop(); 255 | var table = stack.Pop(); 256 | stack.Push(table[key]); 257 | stack.Push(table); 258 | } 259 | 260 | } 261 | } 262 | 263 | -------------------------------------------------------------------------------- /src/Libraries/BasicLibrary.cs: -------------------------------------------------------------------------------- 1 | /* 2 | BasicLibrary.cs: Lua Basic Library 3 | http://www.lua.org/manual/5.1/manual.html#5.1 4 | 5 | Copyright (c) 2011 Alexander Corrado 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | using System; 27 | using System.Linq; 28 | using System.Text; 29 | 30 | using AluminumLua.Executors; 31 | 32 | namespace AluminumLua { 33 | 34 | public partial class LuaContext { 35 | 36 | public void AddBasicLibrary () 37 | { 38 | SetGlobal ("print", print); 39 | SetGlobal ("dofile", dofile); 40 | SetGlobal ("type", type); 41 | } 42 | 43 | private LuaObject print (LuaObject [] args) 44 | { 45 | var first = true; 46 | var buf = new StringBuilder (); 47 | 48 | foreach (var arg in args) { 49 | 50 | if (!first) 51 | buf.Append ('\t'); 52 | 53 | buf.Append (arg.ToString ()); 54 | first = false; 55 | } 56 | 57 | Console.WriteLine (buf.ToString ()); 58 | return true; 59 | } 60 | 61 | private LuaObject dofile (LuaObject [] args) 62 | { 63 | LuaParser parser; 64 | 65 | var exec = LuaSettings.Executor (this); 66 | var file = args.FirstOrDefault (); 67 | 68 | if (file.IsNil) 69 | parser = new LuaParser (exec); // read from stdin 70 | else 71 | parser = new LuaParser (exec, file.AsString ()); 72 | 73 | parser.Parse (); 74 | 75 | return exec.Result (); 76 | } 77 | 78 | private LuaObject type (LuaObject [] args) 79 | { 80 | return Enum.GetName (typeof (LuaType), args.First ().Type); 81 | } 82 | } 83 | } 84 | 85 | -------------------------------------------------------------------------------- /src/Libraries/IoLibrary.cs: -------------------------------------------------------------------------------- 1 | /* 2 | IoLibrary.cs: Lua I/O Library 3 | http://www.lua.org/manual/5.1/manual.html#5.7 4 | 5 | Copyright (c) 2011 Alexander Corrado 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | using System; 27 | using System.Linq; 28 | 29 | namespace AluminumLua { 30 | 31 | public partial class LuaContext { 32 | 33 | public void AddIoLibrary () 34 | { 35 | // FIXME: This doesn't work.. we need a way to handle dot notation for tables anyway 36 | SetGlobal ("io.write", io_write); 37 | } 38 | 39 | private LuaObject io_write (LuaObject [] args) 40 | { 41 | foreach (var arg in args) { 42 | 43 | if (arg.IsString) 44 | Console.Write (arg.AsString ()); 45 | 46 | else if (arg.IsNumber) 47 | Console.Write (arg.AsNumber ()); 48 | 49 | else 50 | throw new LuaException ("bad argument to write"); 51 | 52 | } 53 | 54 | return true; 55 | } 56 | 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /src/LinkedDictionary.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using System.Linq.Expressions; 4 | 5 | namespace System.Collections.Generic 6 | { 7 | public class LinkedDictionary : IDictionary, ICollection>, IEnumerable> 8 | { 9 | private Dictionary _Self; 10 | private IDictionary _Parent; 11 | 12 | public LinkedDictionary(IDictionary Parent) 13 | { 14 | _Parent = Parent; 15 | _Self = new Dictionary(); 16 | } 17 | 18 | public void Add(TKey key, TValue value) 19 | { 20 | _Self.Add(key, value); 21 | } 22 | 23 | public bool ContainsKey(TKey key) 24 | { 25 | return _Self.ContainsKey(key) || _Parent.ContainsKey(key); 26 | } 27 | 28 | public ICollection Keys 29 | { 30 | get { return _Self.Keys.Concat(_Parent.Keys).ToList(); } 31 | } 32 | 33 | public bool Remove(TKey key) 34 | { 35 | return _Self.Remove(key); 36 | } 37 | 38 | public bool RemoveRecursive(TKey key) 39 | { 40 | return _Self.ContainsKey(key) ? _Self.Remove(key) : _Parent.Remove(key); 41 | } 42 | 43 | public bool TryGetValue(TKey key, out TValue value) 44 | { 45 | if (!_Self.TryGetValue(key, out value)) 46 | return _Parent.TryGetValue(key, out value); 47 | return true; 48 | } 49 | 50 | public ICollection Values 51 | { 52 | get { return _Self.Values.Concat(_Parent.Values).ToList(); } 53 | } 54 | 55 | public TValue this[TKey key] 56 | { 57 | get 58 | { 59 | return _Self.ContainsKey(key) ? _Self[key] : _Parent[key]; 60 | } 61 | set 62 | { 63 | _Self[key] = value; 64 | } 65 | } 66 | 67 | public void Add(KeyValuePair item) 68 | { 69 | this.Add(item.Key, item.Value); 70 | } 71 | 72 | public void Clear() 73 | { 74 | _Self.Clear(); 75 | } 76 | 77 | public bool Contains(KeyValuePair item) 78 | { 79 | return _Self.Contains(item) || _Parent.Contains(item); 80 | } 81 | 82 | public void CopyTo(KeyValuePair[] array, int arrayIndex) 83 | { 84 | throw new System.NotImplementedException(); 85 | } 86 | 87 | public int Count 88 | { 89 | get { return _Self.Count + _Parent.Count; } 90 | } 91 | 92 | public bool IsReadOnly 93 | { 94 | get { throw new System.NotImplementedException(); } 95 | } 96 | 97 | public bool Remove(KeyValuePair item) 98 | { 99 | throw new System.NotImplementedException(); 100 | } 101 | 102 | public IEnumerator> GetEnumerator() 103 | { 104 | return _Self.GetEnumerator(); 105 | } 106 | 107 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() 108 | { 109 | return _Self.GetEnumerator(); 110 | } 111 | 112 | void ICollection>.Add(KeyValuePair item) 113 | { 114 | throw new System.NotImplementedException(); 115 | } 116 | 117 | void ICollection>.Clear() 118 | { 119 | throw new System.NotImplementedException(); 120 | } 121 | 122 | bool ICollection>.Contains(KeyValuePair item) 123 | { 124 | throw new System.NotImplementedException(); 125 | } 126 | 127 | void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) 128 | { 129 | throw new System.NotImplementedException(); 130 | } 131 | 132 | int ICollection>.Count 133 | { 134 | get { throw new System.NotImplementedException(); } 135 | } 136 | 137 | bool ICollection>.IsReadOnly 138 | { 139 | get { throw new System.NotImplementedException(); } 140 | } 141 | 142 | bool ICollection>.Remove(KeyValuePair item) 143 | { 144 | throw new System.NotImplementedException(); 145 | } 146 | 147 | IEnumerator> IEnumerable>.GetEnumerator() 148 | { 149 | return this.GetEnumerator(); 150 | } 151 | 152 | void IDictionary.Add(TKey key, TValue value) 153 | { 154 | _Self.Add(key, value); 155 | } 156 | 157 | bool IDictionary.ContainsKey(TKey key) 158 | { 159 | return this.ContainsKey(key); 160 | } 161 | 162 | ICollection IDictionary.Keys 163 | { 164 | get { return this.Keys; } 165 | } 166 | 167 | bool IDictionary.Remove(TKey key) 168 | { 169 | return this.Remove(key); 170 | } 171 | 172 | bool IDictionary.TryGetValue(TKey key, out TValue value) 173 | { 174 | return this.TryGetValue(key, out value); 175 | } 176 | 177 | ICollection IDictionary.Values 178 | { 179 | get { return this.Values; } 180 | } 181 | 182 | TValue IDictionary.this[TKey key] 183 | { 184 | get 185 | { 186 | return this[key]; 187 | } 188 | set 189 | { 190 | this[key] = value; 191 | } 192 | } 193 | } 194 | } -------------------------------------------------------------------------------- /src/LuaContext.cs: -------------------------------------------------------------------------------- 1 | /* 2 | LuaContext.cs: Represents a scope 3 | 4 | Copyright (c) 2011 Alexander Corrado 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | 26 | using System; 27 | using System.Collections.Generic; 28 | 29 | namespace AluminumLua { 30 | 31 | public partial class LuaContext { 32 | // (see libraries) 33 | 34 | private IDictionary variables; 35 | public IDictionary Variables 36 | { 37 | get { 38 | if (variables == null) 39 | variables = new Dictionary(); 40 | 41 | return variables; 42 | } 43 | } 44 | 45 | protected LuaContext Parent { get; private set; } 46 | 47 | public LuaContext (LuaContext parent) 48 | { 49 | this.Parent = parent; 50 | 51 | if (Parent.variables != null) 52 | this.variables = new LinkedDictionary (parent.variables); 53 | } 54 | 55 | public LuaContext () 56 | { 57 | SetGlobal ("true", LuaObject.True); 58 | SetGlobal ("false", LuaObject.False); 59 | SetGlobal ("nil", LuaObject.Nil); 60 | } 61 | 62 | public LuaObject Get (string name) 63 | { 64 | LuaObject val; 65 | Variables.TryGetValue (name, out val); 66 | return val; 67 | } 68 | 69 | public bool IsDefined (string name) 70 | { 71 | return Variables.ContainsKey (name); 72 | } 73 | 74 | public void Define (string name) 75 | { 76 | if (!IsDefined (name)) 77 | Variables.Add (name, LuaObject.Nil); 78 | } 79 | 80 | public void SetLocal (string name, LuaObject val) 81 | { 82 | if (Variables.ContainsKey (name)) 83 | Variables.Remove (name); 84 | 85 | if (!val.IsNil) 86 | Variables.Add (name, val); 87 | } 88 | public void SetLocal (string name, LuaFunction fn) 89 | { 90 | SetLocal (name, LuaObject.FromFunction (fn)); 91 | } 92 | 93 | public void SetGlobal (string name, LuaObject val) 94 | { 95 | SetLocal (name, val); 96 | if (Parent != null) 97 | Parent.SetGlobal (name, val); 98 | } 99 | public void SetGlobal (string name, LuaFunction fn) 100 | { 101 | SetGlobal (name, LuaObject.FromFunction (fn)); 102 | } 103 | 104 | 105 | public void SetLocalAndParent (string name, LuaObject val) 106 | { 107 | SetLocal (name, val); 108 | Parent.SetLocal (name, val); 109 | } 110 | public void SetLocalAndParent (string name, LuaFunction fn) 111 | { 112 | SetLocalAndParent (name, LuaObject.FromFunction(fn)); 113 | } 114 | } 115 | } 116 | 117 | -------------------------------------------------------------------------------- /src/LuaObject.cs: -------------------------------------------------------------------------------- 1 | /* 2 | LuaObject.cs: Lua object abstraction 3 | 4 | Copyright (c) 2011 Alexander Corrado 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using System; 26 | using System.Linq; 27 | using System.Collections; 28 | using System.Collections.Generic; 29 | using System.Threading; 30 | 31 | namespace AluminumLua { 32 | 33 | using LuaTable = IDictionary; 34 | using LuaTableImpl = Dictionary; 35 | using LuaTableItem = KeyValuePair; 36 | 37 | public delegate LuaObject LuaFunction (LuaObject [] args); 38 | 39 | // http://www.lua.org/pil/2.html 40 | public enum LuaType { 41 | nil, 42 | boolean, 43 | number, 44 | @string, 45 | userdata, 46 | function, 47 | thread, 48 | table 49 | }; 50 | 51 | public struct LuaObject : IEnumerable>, IEquatable { 52 | 53 | private object luaobj; 54 | private LuaType type; 55 | 56 | // pre-create some common values 57 | public static readonly LuaObject Nil = new LuaObject (); 58 | public static readonly LuaObject True = new LuaObject { luaobj = true, type = LuaType.boolean }; 59 | public static readonly LuaObject False = new LuaObject { luaobj = false, type = LuaType.boolean }; 60 | public static readonly LuaObject Zero = new LuaObject { luaobj = 0d, type = LuaType.number }; 61 | public static readonly LuaObject EmptyString = new LuaObject { luaobj = "", type = LuaType.@string }; 62 | 63 | public LuaType Type { get { return type; } } 64 | 65 | public bool Is (LuaType type) 66 | { 67 | return this.type == type; 68 | } 69 | 70 | 71 | public static LuaObject FromBool (bool bln) 72 | { 73 | if (bln) 74 | return True; 75 | 76 | return False; 77 | } 78 | public static implicit operator LuaObject (bool bln) 79 | { 80 | return FromBool (bln); 81 | } 82 | public static LuaObject FromDelegate(Delegate a) 83 | { 84 | return FromFunction((args) => DelegateAdapter(a, args)); 85 | } 86 | public static LuaObject FromObject(object obj) 87 | { 88 | if (obj == null) 89 | return Nil; 90 | if (obj is LuaObject) 91 | return (LuaObject)obj; 92 | 93 | if (obj is bool) 94 | return FromBool((bool)obj); 95 | 96 | { 97 | var str = obj as string; 98 | if (str != null) 99 | { 100 | return FromString(str); 101 | } 102 | } 103 | 104 | { 105 | var @delegate = obj as LuaFunction; 106 | if (@delegate != null) 107 | { 108 | return FromFunction(@delegate); 109 | } 110 | } 111 | 112 | { 113 | var @delegate = obj as Delegate; 114 | if (@delegate != null) 115 | { 116 | return FromDelegate(@delegate); 117 | } 118 | } 119 | 120 | { 121 | var dictionary = obj as LuaTable; 122 | if (dictionary != null) 123 | { 124 | return FromTable(dictionary); 125 | } 126 | } 127 | 128 | if (obj is double) return FromNumber((double)obj); 129 | if (obj is float) return FromNumber((float)obj); 130 | if (obj is int) return FromNumber((int)obj); 131 | if (obj is uint) return FromNumber((uint)obj); 132 | if (obj is short) return FromNumber((short)obj); 133 | if (obj is ushort) return FromNumber((ushort)obj); 134 | if (obj is long) return FromNumber((long)obj); 135 | if (obj is ulong) return FromNumber((ulong)obj); 136 | if (obj is byte) return FromNumber((byte)obj); 137 | if (obj is sbyte) return FromNumber((sbyte)obj); 138 | if (obj is Thread) return new LuaObject { luaobj = obj, type = LuaType.thread }; 139 | return FromUserData(obj); 140 | } 141 | 142 | private static LuaObject DelegateAdapter(Delegate @delegate, IEnumerable args) 143 | { 144 | return FromObject(@delegate.DynamicInvoke((from a in args select a.luaobj).ToArray())); 145 | } 146 | 147 | public static LuaObject FromNumber (double number) 148 | { 149 | if (number == 0d) 150 | return Zero; 151 | 152 | return new LuaObject { luaobj = number, type = LuaType.number }; 153 | } 154 | public static implicit operator LuaObject (double number) 155 | { 156 | return FromNumber (number); 157 | } 158 | 159 | public static LuaObject FromString (string str) 160 | { 161 | if (str == null) 162 | return Nil; 163 | 164 | if (str.Length == 0) 165 | return EmptyString; 166 | 167 | return new LuaObject { luaobj = str, type = LuaType.@string }; 168 | } 169 | public static implicit operator LuaObject (string str) 170 | { 171 | return FromString (str); 172 | } 173 | 174 | public static LuaObject FromTable (LuaTable table) 175 | { 176 | if (table == null) 177 | return Nil; 178 | 179 | return new LuaObject { luaobj = table, type = LuaType.table }; 180 | } 181 | public static LuaObject FromUserData(object userdata) 182 | { 183 | if (userdata == null) 184 | return Nil; 185 | 186 | return new LuaObject { luaobj = userdata, type = LuaType.userdata }; 187 | } 188 | public static LuaObject NewTable (params LuaTableItem [] initItems) 189 | { 190 | var table = FromTable (new LuaTableImpl ()); 191 | 192 | foreach (var item in initItems) 193 | table [item.Key] = item.Value; 194 | 195 | return table; 196 | } 197 | 198 | public static LuaObject FromFunction (LuaFunction fn) 199 | { 200 | if (fn == null) 201 | return Nil; 202 | 203 | return new LuaObject { luaobj = fn, type = LuaType.function }; 204 | } 205 | public static implicit operator LuaObject (LuaFunction fn) 206 | { 207 | return FromFunction (fn); 208 | } 209 | 210 | public bool IsNil { get { return type == LuaType.nil; } } 211 | 212 | public bool IsBool { get { return type == LuaType.boolean; } } 213 | public bool AsBool () 214 | { 215 | if (luaobj == null) 216 | return false; 217 | 218 | if (luaobj is bool && ((bool)luaobj) == false) 219 | return false; 220 | 221 | return true; 222 | } 223 | 224 | public bool IsNumber { get { return type == LuaType.number; } } 225 | public double AsNumber () 226 | { 227 | return (double)luaobj; 228 | } 229 | public bool IsUserData { get { return type == LuaType.userdata; } } 230 | public object AsUserData() 231 | { 232 | return luaobj; 233 | } 234 | public bool IsString { get { return type == LuaType.@string; } } 235 | public string AsString () 236 | { 237 | return luaobj.ToString (); 238 | } 239 | 240 | public bool IsFunction { get { return type == LuaType.function; } } 241 | public LuaFunction AsFunction () 242 | { 243 | var fn = luaobj as LuaFunction; 244 | if (fn == null) 245 | throw new LuaException ("cannot call non-function"); 246 | 247 | return fn; 248 | } 249 | 250 | public bool IsTable { get { return type == LuaType.table; } } 251 | public LuaTable AsTable () { 252 | return luaobj as LuaTable; 253 | } 254 | 255 | 256 | public IEnumerator> GetEnumerator () 257 | { 258 | var table = luaobj as IEnumerable>; 259 | if (table == null) 260 | return null; 261 | 262 | return table.GetEnumerator (); 263 | } 264 | 265 | IEnumerator IEnumerable.GetEnumerator () 266 | { 267 | return GetEnumerator (); 268 | } 269 | 270 | public LuaObject this [LuaObject key] { 271 | get { 272 | var table = AsTable (); 273 | if (table == null) 274 | throw new LuaException ("cannot index non-table"); 275 | 276 | // we don't care whether the get was successful, because the default LuaObject is nil. 277 | LuaObject result; 278 | table.TryGetValue (key, out result); 279 | return result; 280 | } 281 | set { 282 | var table = AsTable (); 283 | if (table == null) 284 | throw new LuaException ("cannot index non-table"); 285 | 286 | table [key] = value; 287 | } 288 | } 289 | 290 | // Unlike AsString, this will return string representations of nil, tables, and functions 291 | public override string ToString () 292 | { 293 | if (IsNil) 294 | return "nil"; 295 | 296 | if (IsTable) 297 | return "{ " + string.Join (", ", AsTable ().Select (kv => string.Format ("[{0}]={1}", kv.Key, kv.Value.ToString ())).ToArray ()) + " }"; 298 | 299 | if (IsFunction) 300 | return AsFunction ().Method.ToString (); 301 | 302 | return luaobj.ToString (); 303 | } 304 | 305 | // See last paragraph in http://www.lua.org/pil/13.2.html 306 | public bool Equals (LuaObject other) 307 | { 308 | // luaobj will not be null unless type is Nil 309 | return (other.type == type) && (luaobj == null || luaobj.Equals (other.luaobj)); 310 | } 311 | 312 | public override bool Equals (object obj) 313 | { 314 | if (obj is LuaObject) 315 | return Equals ((LuaObject)obj); 316 | // FIXME: It would be nice to automatically compare other types (strings, ints, doubles, etc.) to LuaObjects. 317 | return false; 318 | } 319 | 320 | public override int GetHashCode () 321 | { 322 | unchecked { 323 | return (luaobj != null ? luaobj.GetHashCode () : 0) ^ type.GetHashCode (); 324 | } 325 | } 326 | } 327 | } 328 | 329 | -------------------------------------------------------------------------------- /src/LuaParser.cs: -------------------------------------------------------------------------------- 1 | /* 2 | LuaParser.cs: Handwritten Lua parser 3 | 4 | Copyright (c) 2011 Alexander Corrado 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | // Please note: Work in progress. 26 | // For instance, there is little support for Lua statement types beside function calls 27 | 28 | using System; 29 | using System.IO; 30 | using System.Linq.Expressions; 31 | using System.Collections; 32 | using System.Collections.Generic; 33 | using System.Text; 34 | using System.Text.RegularExpressions; 35 | using System.Globalization; 36 | 37 | using AluminumLua.Executors; 38 | 39 | namespace AluminumLua { 40 | 41 | public class LuaParser : IDisposable 42 | { 43 | ~LuaParser() 44 | { 45 | this.Dispose(false); 46 | } 47 | protected string file_name; 48 | protected TextReader input; 49 | 50 | private bool closeInputStream; 51 | 52 | protected bool eof, OptionKeyword; 53 | protected int row, col, scope_count; 54 | 55 | protected IExecutor CurrentExecutor { get; set; } 56 | 57 | public LuaParser(IExecutor executor, string file) 58 | { 59 | this.file_name = Path.GetFileName(file); 60 | this.input = File.OpenText(file); 61 | this.closeInputStream = true; 62 | this.row = 1; 63 | this.col = 1; 64 | 65 | this.CurrentExecutor = executor; 66 | } 67 | 68 | public LuaParser(LuaContext ctx, string file) 69 | : this(LuaSettings.Executor(ctx), file) 70 | { 71 | } 72 | 73 | public LuaParser(IExecutor executor) 74 | { 75 | this.file_name = "stdin"; 76 | #if WINDOWS_PHONE || SILVERLIGHT 77 | this.input = Console.In; 78 | #else 79 | this.input = new StreamReader (Console.OpenStandardInput ()); 80 | #endif 81 | this.CurrentExecutor = executor; 82 | } 83 | 84 | public LuaParser(LuaContext ctx, TextReader stream) 85 | : this(LuaSettings.Executor(ctx), stream) 86 | { 87 | } 88 | public LuaParser(IExecutor executor, TextReader stream) 89 | { 90 | this.file_name = "stream"; 91 | this.input = stream; 92 | this.CurrentExecutor = executor; 93 | } 94 | 95 | public LuaParser(LuaContext ctx) 96 | : this(LuaSettings.Executor(ctx)) 97 | { 98 | } 99 | 100 | public void Parse() 101 | { 102 | Parse(false); 103 | } 104 | 105 | public void Parse(bool interactive) 106 | { 107 | do 108 | { 109 | 110 | var identifier = ParseLVal(); 111 | 112 | if (eof) 113 | break; 114 | 115 | switch (identifier) 116 | { 117 | 118 | case "function": 119 | ParseFunctionDefStatement(false); 120 | break; 121 | 122 | case "do": 123 | scope_count++; 124 | CurrentExecutor.PushScope(); 125 | break; 126 | 127 | case "else": 128 | case "end": 129 | if (--scope_count < 0) 130 | { 131 | scope_count = 0; 132 | Err("unexpected 'end'"); 133 | } 134 | OptionKeyword = identifier == "else"; 135 | CurrentExecutor.PopScope(); 136 | break; 137 | 138 | case "local": 139 | var name = ParseLVal(); 140 | if (name == "function") 141 | ParseFunctionDefStatement(true); 142 | else 143 | ParseAssign(name, true); 144 | break; 145 | 146 | case "return": 147 | ParseRVal(); 148 | CurrentExecutor.Return(); 149 | break; 150 | 151 | case "if": 152 | ParseConditionalStatement(); 153 | if (CurrentExecutor is CompilerExecutor) CurrentExecutor.PopStack(); 154 | break; 155 | default: 156 | if (Peek() == '=') 157 | { 158 | ParseAssign(identifier, false); 159 | break; 160 | } 161 | 162 | CurrentExecutor.Variable(identifier); 163 | ParseLValOperator(); 164 | break; 165 | } 166 | 167 | } while (!eof && !interactive); 168 | } 169 | 170 | protected string ParseLVal() 171 | { 172 | var val = ParseOne(false); 173 | if (val == null && !eof) 174 | Err("expected identifier"); 175 | 176 | return val; 177 | } 178 | 179 | protected void ParseLValOperator() 180 | { 181 | var isTerminal = false; 182 | 183 | while (true) 184 | { 185 | 186 | switch (Peek()) 187 | { 188 | 189 | case '[': 190 | case '.': 191 | ParseTableAccess(); 192 | isTerminal = false; 193 | 194 | // table assign is special 195 | if (Peek() == '=') 196 | { 197 | Consume(); 198 | ParseRVal(); 199 | CurrentExecutor.TableSet(); 200 | return; 201 | } 202 | break; 203 | case ':': 204 | ParseColonOperator(); 205 | isTerminal = true; 206 | break; 207 | 208 | case '(': 209 | case '{': 210 | case '"': 211 | case '\'': 212 | ParseCall(0); 213 | isTerminal = true; 214 | break; 215 | 216 | default: 217 | if (isTerminal) 218 | { 219 | CurrentExecutor.PopStack(); 220 | return; 221 | } 222 | Err("syntax error"); 223 | break; 224 | } 225 | } 226 | } 227 | 228 | protected void ParseRVal() 229 | { 230 | var identifier = ParseOne(true); 231 | 232 | if (identifier != null) 233 | { 234 | switch (identifier) 235 | { 236 | 237 | case "function": 238 | var currentScope = scope_count; 239 | CurrentExecutor.PushFunctionScope(ParseArgDefList()); 240 | scope_count++; 241 | 242 | while (scope_count > currentScope) 243 | Parse(true); 244 | break; 245 | 246 | case "not": 247 | ParseRVal(); 248 | CurrentExecutor.Negate(); 249 | break; 250 | 251 | default: 252 | CurrentExecutor.Variable(identifier); 253 | break; 254 | } 255 | } 256 | 257 | while (TryParseOperator()) { /* do it */ } 258 | } 259 | 260 | protected bool TryParseOperator() 261 | { 262 | var next = Peek(); 263 | 264 | switch (next) 265 | { 266 | 267 | case '[': 268 | ParseTableAccess(); 269 | break; 270 | 271 | case '.': 272 | ParseTableAccessOrConcatenation(); 273 | break; 274 | case ':': 275 | this.ParseColonOperator(); 276 | break; 277 | case '(': 278 | case '{': 279 | case '"': 280 | case '\'': 281 | ParseCall(0); 282 | break; 283 | 284 | // FIXME: ORDER OF OPERATIONS! 285 | case '+': 286 | Consume(); 287 | ParseRVal(); 288 | CurrentExecutor.Add(); 289 | break; 290 | 291 | case '-': 292 | Consume(); 293 | ParseRVal(); 294 | CurrentExecutor.Subtract(); 295 | break; 296 | 297 | case '*': 298 | Consume(); 299 | ParseRVal(); 300 | CurrentExecutor.Multiply(); 301 | break; 302 | 303 | case '/': 304 | Consume(); 305 | ParseRVal(); 306 | CurrentExecutor.Divide(); 307 | break; 308 | 309 | case 'o': 310 | case 'O': 311 | Consume(); 312 | if (char.ToLowerInvariant(Consume()) != 'r') 313 | Err("unexpected 'o'"); 314 | ParseRVal(); 315 | CurrentExecutor.Or(); 316 | break; 317 | 318 | case 'a': 319 | case 'A': 320 | Consume(); 321 | if (char.ToLowerInvariant(Consume()) != 'n') 322 | Err("unexpected 'a'"); 323 | if (char.ToLowerInvariant(Consume()) != 'd') 324 | Err("unexpected 'an'"); 325 | ParseRVal(); 326 | CurrentExecutor.And(); 327 | break; 328 | case '>': 329 | Consume(); 330 | bool OrEqual = Peek() == '='; 331 | if (OrEqual) Consume(); 332 | ParseRVal(); 333 | if (OrEqual) CurrentExecutor.GreaterOrEqual(); else CurrentExecutor.Greater(); 334 | break; 335 | case '<': 336 | Consume(); 337 | bool OrEqual2 = Peek() == '='; 338 | if (OrEqual2) Consume(); 339 | ParseRVal(); 340 | if (OrEqual2) CurrentExecutor.SmallerOrEqual(); else CurrentExecutor.Smaller(); 341 | break; 342 | case '=': 343 | Consume(); 344 | if (Consume() != '=') 345 | Err("unexpected '='"); 346 | ParseRVal(); 347 | CurrentExecutor.Equal(); 348 | break; 349 | 350 | case '~': 351 | Consume(); 352 | if (Consume() != '=') 353 | Err("unexpected '~'"); 354 | ParseRVal(); 355 | CurrentExecutor.NotEqual(); 356 | break; 357 | 358 | default: 359 | return false; 360 | } 361 | 362 | return true; 363 | } 364 | 365 | protected void ParseAssign(string identifier, bool localScope) 366 | { 367 | Consume('='); 368 | ParseRVal(); // push value 369 | 370 | CurrentExecutor.Assign(identifier, localScope); 371 | } 372 | 373 | protected void ParseCall(int args) 374 | { 375 | int argCount = args; 376 | var next = Peek(); 377 | 378 | if (next == '"' || next == '\'' || next == '{') 379 | { 380 | // function call with 1 arg only.. must be string or table 381 | 382 | ParseRVal(); 383 | ++argCount; 384 | 385 | } 386 | else if (next == '(') 387 | { 388 | // function call 389 | 390 | Consume(); 391 | 392 | next = Peek(); 393 | while (next != ')') 394 | { 395 | 396 | ParseRVal(); 397 | ++argCount; 398 | 399 | next = Peek(); 400 | if (next == ',') 401 | { 402 | Consume(); 403 | next = Peek(); 404 | 405 | } 406 | else if (next != ')') 407 | { 408 | 409 | Err("expecting ',' or ')'"); 410 | } 411 | } 412 | 413 | Consume(')'); 414 | 415 | } 416 | else 417 | { 418 | 419 | Err("expecting string, table, or '('"); 420 | } 421 | 422 | CurrentExecutor.Call(argCount); 423 | } 424 | 425 | protected void ParseConditionalStatement() 426 | { 427 | ParseRVal(); 428 | if (!( 429 | char.ToLowerInvariant(Consume()) == 't' && 430 | char.ToLowerInvariant(Consume()) == 'h' && 431 | char.ToLowerInvariant(Consume()) == 'e' && 432 | char.ToLowerInvariant(Consume()) == 'n')) Err("Expected 'then'"); 433 | 434 | var currentScope = scope_count; 435 | CurrentExecutor.PushBlockScope(); 436 | scope_count++; 437 | 438 | while (scope_count > currentScope && !eof) 439 | Parse(true); 440 | if (eof) { CurrentExecutor.PopScope(); OptionKeyword = false; } 441 | 442 | if (OptionKeyword) 443 | { 444 | currentScope = scope_count; 445 | CurrentExecutor.PushBlockScope(); 446 | scope_count++; 447 | 448 | while (scope_count > currentScope && !eof) 449 | Parse(true); 450 | if (eof) CurrentExecutor.PopScope(); 451 | } 452 | else 453 | { 454 | CurrentExecutor.PushBlockScope(); 455 | CurrentExecutor.PopScope(); 456 | } 457 | 458 | CurrentExecutor.IfThenElse(); 459 | } 460 | 461 | protected void ParseFunctionDefStatement(bool localScope) 462 | { 463 | var name = ParseLVal(); 464 | var next = Peek(); 465 | bool isTableSet = (next == '.'); 466 | 467 | if (isTableSet) 468 | { 469 | 470 | CurrentExecutor.Variable(name); // push (first) table 471 | Consume(); // '.' 472 | CurrentExecutor.Constant(ParseLVal()); // push key 473 | 474 | next = Peek(); 475 | 476 | while (next == '.') 477 | { 478 | 479 | CurrentExecutor.TableGet(); // push (subsequent) table 480 | Consume(); // '.' 481 | CurrentExecutor.Constant(ParseLVal()); // push key 482 | 483 | next = Peek(); 484 | } 485 | } 486 | 487 | var currentScope = scope_count; 488 | CurrentExecutor.PushFunctionScope(ParseArgDefList()); 489 | scope_count++; 490 | 491 | while (scope_count > currentScope) 492 | Parse(true); 493 | 494 | if (isTableSet) 495 | CurrentExecutor.TableSet(); 496 | else 497 | CurrentExecutor.Assign(name, localScope); 498 | } 499 | 500 | // parses named argument list in func definition 501 | protected string[] ParseArgDefList() 502 | { 503 | Consume('('); 504 | 505 | var args = new List(); 506 | var next = Peek(); 507 | 508 | while (next != ')') 509 | { 510 | 511 | args.Add(ParseLVal()); 512 | 513 | next = Peek(); 514 | if (next == ',') 515 | { 516 | Consume(); 517 | next = Peek(); 518 | 519 | } 520 | else if (next != ')') 521 | { 522 | 523 | Err("expecting ',' or ')'"); 524 | } 525 | } 526 | 527 | Consume(')'); 528 | return args.ToArray(); 529 | } 530 | 531 | protected void ParseColonOperator() 532 | { 533 | var next = Peek(); 534 | 535 | if (next != ':') 536 | Err("expected ':'"); 537 | 538 | 539 | Consume(); 540 | 541 | CurrentExecutor.Constant(ParseLVal()); // push key 542 | CurrentExecutor.ColonOperator(); 543 | 544 | next = Peek(); 545 | 546 | if (next != '(') 547 | Err("expected '('"); 548 | 549 | this.ParseCall(1); 550 | 551 | //throw new NotImplementedException("colon operator is not implemented yet"); 552 | } 553 | 554 | // assumes that the table has already been pushed 555 | protected void ParseTableAccess() 556 | { 557 | var next = Peek(); 558 | 559 | if (next != '[' && next != '.') 560 | Err("expected '[' or '.'"); 561 | 562 | Consume(); 563 | 564 | switch (next) 565 | { 566 | 567 | case '[': 568 | ParseRVal(); // push key 569 | Consume(']'); 570 | break; 571 | 572 | case '.': 573 | CurrentExecutor.Constant(ParseLVal()); // push key 574 | break; 575 | 576 | } 577 | 578 | if (Peek() != '=') 579 | CurrentExecutor.TableGet(); 580 | } 581 | 582 | // assumes that the first item has already been pushed 583 | protected void ParseTableAccessOrConcatenation() 584 | { 585 | Consume('.'); 586 | var next = Peek(); 587 | 588 | if (next == '.') 589 | { 590 | // concatenation 591 | 592 | Consume(); 593 | ParseRVal(); 594 | CurrentExecutor.Concatenate(); 595 | 596 | } 597 | else 598 | { 599 | // table access 600 | 601 | CurrentExecutor.Constant(ParseLVal()); 602 | CurrentExecutor.TableGet(); 603 | 604 | } 605 | } 606 | 607 | // ----- 608 | 609 | // Parses a single value or identifier 610 | // Identifiers come out as strings 611 | protected string ParseOne(bool expr) 612 | { 613 | top: 614 | var la = Peek(); 615 | switch (la) 616 | { 617 | 618 | case (char)0: eof = true; break; 619 | 620 | case ';': 621 | Consume(); 622 | goto top; 623 | 624 | case '-': 625 | Consume(); 626 | if (Peek() == '-') 627 | { 628 | ParseComment(); 629 | goto top; 630 | 631 | } 632 | else if (expr) 633 | { 634 | 635 | ParseRVal(); 636 | CurrentExecutor.Constant(LuaObject.FromNumber(-1)); 637 | CurrentExecutor.Multiply(); 638 | } 639 | break; 640 | 641 | case '"': if (expr) CurrentExecutor.Constant(ParseStringLiteral()); break; 642 | case '\'': if (expr) CurrentExecutor.Constant(ParseStringLiteral()); break; 643 | case '{': if (expr) ParseTableLiteral(); break; 644 | 645 | case '(': 646 | if (expr) 647 | { 648 | Consume(); 649 | ParseRVal(); 650 | Consume(')'); 651 | } 652 | break; 653 | 654 | default: 655 | if (char.IsLetter(la)) 656 | return ParseIdentifier(); 657 | 658 | if (expr && (char.IsDigit(la) || la == '.')) 659 | CurrentExecutor.Constant(ParseNumberLiteral()); 660 | else 661 | Err("unexpected '{0}'", la); 662 | break; 663 | } 664 | 665 | return null; //? 666 | } 667 | 668 | // http://www.lua.org/pil/3.6.html 669 | protected void ParseTableLiteral() 670 | { 671 | Consume('{'); 672 | 673 | int i = 1; 674 | int count = 0; 675 | var next = Peek(); 676 | 677 | while (next != '}' && !eof) 678 | { 679 | count++; 680 | 681 | if (next == '[') 682 | { 683 | Consume(); 684 | ParseRVal(); 685 | Consume(']'); 686 | Consume('='); 687 | 688 | } 689 | else 690 | { //array style 691 | 692 | CurrentExecutor.Constant(LuaObject.FromNumber(i++)); 693 | } 694 | 695 | ParseRVal(); 696 | 697 | next = Peek(); 698 | if (next == ',') 699 | { 700 | 701 | Consume(); 702 | next = Peek(); 703 | 704 | } 705 | else if (next != '}') 706 | { 707 | 708 | Err("expecting ',' or '}'"); 709 | } 710 | } 711 | 712 | CurrentExecutor.TableCreate(count); 713 | 714 | Consume('}'); 715 | } 716 | 717 | protected LuaObject ParseNumberLiteral() 718 | { 719 | var next = Peek(); 720 | var sb = new StringBuilder(); 721 | 722 | while (char.IsDigit(next) || next == '-' || next == '.' || next == 'e' || next == 'E') 723 | { 724 | Consume(); 725 | sb.Append(next); 726 | next = Peek(true); 727 | } 728 | 729 | var val = double.Parse(sb.ToString(), CultureInfo.InvariantCulture); 730 | return LuaObject.FromNumber(val); 731 | } 732 | 733 | 734 | // FIXME: Handle multi line strings 735 | // http://www.lua.org/pil/2.4.html 736 | protected LuaObject ParseStringLiteral() 737 | { 738 | var next = Peek(); 739 | var sb = new StringBuilder(); 740 | var escaped = false; 741 | 742 | if (next != '"' && next != '\'') 743 | Err("expected string"); 744 | 745 | var quote = next; 746 | 747 | Consume(); 748 | next = Consume(); 749 | 750 | while (next != quote || escaped) 751 | { 752 | 753 | if (!escaped && next == '\\') 754 | { 755 | 756 | escaped = true; 757 | 758 | } 759 | else if (escaped) 760 | { 761 | 762 | switch (next) 763 | { 764 | 765 | case 'a': next = '\a'; break; 766 | case 'b': next = '\b'; break; 767 | case 'f': next = '\f'; break; 768 | case 'n': next = '\n'; break; 769 | case 'r': next = '\r'; break; 770 | case 't': next = '\t'; break; 771 | case 'v': next = '\v'; break; 772 | 773 | } 774 | 775 | sb.Append(next); 776 | escaped = false; 777 | } 778 | else 779 | { 780 | 781 | sb.Append(next); 782 | } 783 | 784 | next = Consume(); 785 | } 786 | 787 | return LuaObject.FromString(sb.ToString()); 788 | } 789 | 790 | protected string ParseIdentifier() 791 | { 792 | var next = Peek(); 793 | var sb = new StringBuilder(); 794 | 795 | do 796 | { 797 | Consume(); 798 | sb.Append(next); 799 | next = Peek(true); 800 | } while (char.IsLetterOrDigit(next) || next == '_'); 801 | 802 | return sb.ToString(); 803 | } 804 | 805 | protected void ParseComment() 806 | { 807 | Consume('-'); 808 | if (Peek() == '-') 809 | Consume(); 810 | 811 | if (Consume() == '[' && Consume() == '[') 812 | { 813 | while (!eof && (Consume() != ']' || Consume() != ']')) { /* consume entire block comment */; } 814 | } 815 | else 816 | { 817 | eof = (input.ReadLine() == null); 818 | col = 1; 819 | row++; 820 | } 821 | } 822 | 823 | // scanner primitives: 824 | 825 | protected void Consume(char expected) 826 | { 827 | var actual = Peek(); 828 | if (eof || actual != expected) 829 | Err("expected '{0}'", expected); 830 | 831 | while (Consume() != actual) 832 | { /* eat whitespace */ } 833 | 834 | } 835 | 836 | protected char Consume() 837 | { 838 | var r = input.Read(); 839 | if (r == -1) 840 | { 841 | eof = true; 842 | return (char)0; 843 | } 844 | 845 | col++; 846 | return (char)r; 847 | } 848 | 849 | protected char Peek() 850 | { 851 | return Peek(false); 852 | } 853 | 854 | protected char Peek(bool whitespaceSignificant) 855 | { 856 | top: 857 | var p = input.Peek(); 858 | if (p == -1) 859 | { 860 | eof = true; 861 | return (char)0; 862 | } 863 | 864 | var la = (char)p; 865 | 866 | if (!whitespaceSignificant) 867 | { 868 | if (la == '\r') 869 | { 870 | input.Read(); 871 | if (((char)input.Peek()) == '\n') 872 | input.Read(); 873 | 874 | col = 1; 875 | row++; 876 | goto top; 877 | } 878 | 879 | if (la == '\n') 880 | { 881 | input.Read(); 882 | col = 1; 883 | row++; 884 | goto top; 885 | } 886 | 887 | if (char.IsWhiteSpace(la)) 888 | { 889 | Consume(); 890 | goto top; 891 | } 892 | } 893 | 894 | return la; 895 | } 896 | 897 | 898 | // convenience methods: 899 | 900 | 901 | protected void Err(string message, params object[] args) 902 | { 903 | Consume(); 904 | throw new LuaException(file_name, row, col - 1, string.Format(message, args)); 905 | } 906 | 907 | #region Implementation of IDisposable 908 | 909 | public void Dispose() 910 | { 911 | this.Dispose(true); 912 | GC.SuppressFinalize(this); 913 | } 914 | 915 | public void Dispose(bool isManaged) 916 | { 917 | if (this.closeInputStream) 918 | input.Close(); 919 | } 920 | 921 | #endregion 922 | } 923 | 924 | public class LuaException : Exception { 925 | 926 | public LuaException (string file, int row, int col, string message) 927 | : base (string.Format ("Error in {0}({1},{2}): {3}", file, row, col, message)) 928 | { 929 | } 930 | 931 | public LuaException (string message) 932 | : base ("Error (unknown context): " + message) 933 | { 934 | } 935 | } 936 | } 937 | 938 | -------------------------------------------------------------------------------- /src/LuaSettings.cs: -------------------------------------------------------------------------------- 1 | /* 2 | LuaSettings.cs: Represents settings that can be changed by the hosting program 3 | 4 | Copyright (c) 2011 Alexander Corrado 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using System; 26 | 27 | using AluminumLua.Executors; 28 | 29 | namespace AluminumLua { 30 | 31 | public static class LuaSettings { 32 | 33 | 34 | public static Func Executor = (ctx) => new DefaultExecutor (ctx); 35 | 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /src/Main.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | using AluminumLua.Executors; 5 | 6 | namespace AluminumLua { 7 | 8 | public static class MainClass { 9 | 10 | public static void Main (string [] args) 11 | { 12 | LuaParser parser; 13 | 14 | var context = new LuaContext (); 15 | context.AddBasicLibrary (); 16 | context.AddIoLibrary (); 17 | 18 | if (args.Any ()) { // take first arg as file name 19 | parser = new LuaParser (context, args [0]); 20 | parser.Parse (); 21 | 22 | return; 23 | } 24 | 25 | // otherwise, run repl 26 | Console.WriteLine ("AluminumLua 0.1 (c) 2011 Alex Corrado"); 27 | parser = new LuaParser (context); 28 | while (true) { 29 | try { 30 | Console.Write ("> "); 31 | parser.Parse (true); 32 | } 33 | catch (LuaException e) { 34 | Console.WriteLine (e.Message); 35 | } 36 | } 37 | } 38 | 39 | } 40 | 41 | 42 | } 43 | 44 | -------------------------------------------------------------------------------- /test/dofile.lua: -------------------------------------------------------------------------------- 1 | function go () 2 | print "Calling dofile 'helloworld.lua' ..." 3 | print ("Got:", dofile 'helloworld.lua') 4 | end 5 | 6 | go() -------------------------------------------------------------------------------- /test/dofile.lua.txt: -------------------------------------------------------------------------------- 1 | Calling dofile 'helloworld.lua' ... 2 | Hello world! 3 | Hello lua! 4 | Got: I'm done! 5 | -------------------------------------------------------------------------------- /test/functionscopes.lua: -------------------------------------------------------------------------------- 1 | function cat () 2 | do 3 | local boogie = 'rad' 4 | end 5 | 6 | print (boogie) 7 | end 8 | 9 | -- this should actually print "nil" 10 | cat() 11 | -------------------------------------------------------------------------------- /test/functionscopes.lua.txt: -------------------------------------------------------------------------------- 1 | nil 2 | -------------------------------------------------------------------------------- /test/helloworld.lua: -------------------------------------------------------------------------------- 1 | function sayhello(who) 2 | 3 | print ("Hello", who) 4 | end 5 | 6 | sayhello "world!" 7 | sayhello "lua!" 8 | 9 | return 'I\'m done!' 10 | -------------------------------------------------------------------------------- /test/helloworld.lua.txt: -------------------------------------------------------------------------------- 1 | Hello world! 2 | Hello lua! 3 | -------------------------------------------------------------------------------- /test_action.lua: -------------------------------------------------------------------------------- 1 | -- Register 'test' action with Premake 2 | 3 | newaction { 4 | 5 | trigger = "test", 6 | description = "Run tests; must build first", 7 | execute = function () 8 | print ("") 9 | 10 | local alua_exe = path.getabsolute "alua.exe" 11 | local test_dir = "test" 12 | os.chdir (test_dir) 13 | 14 | if (not os.isfile (alua_exe)) then 15 | print (alua_exe.." not found; did you forget to build?") 16 | return 17 | end 18 | 19 | local tests = os.matchfiles "**.lua" 20 | local cmd = iif (os.is "windows", "", "mono ") .. alua_exe 21 | 22 | local passed = 0 23 | local failed = 0 24 | local total = 0 25 | for _,test in ipairs (tests) do 26 | total = total + 1 27 | 28 | local alua = io.popen (cmd.." "..test) 29 | local txt = io.open (test..".txt") 30 | local line = 1 31 | local didfail = false 32 | 33 | for actual in alua:lines () do 34 | local expected = txt:read "*l" 35 | 36 | if expected == nil then 37 | print ("test:\t", test.." (output line "..line..")") 38 | print ("expected:", "") 39 | print ("but got:", actual) 40 | didfail = true 41 | break 42 | end 43 | 44 | if actual ~= expected then 45 | print ("test:\t",test.." (output line "..line..")") 46 | print ("expected:", expected) 47 | print ("but got:", actual) 48 | didfail = true 49 | break 50 | end 51 | 52 | line = line + 1 53 | end 54 | 55 | if didfail then 56 | failed = failed + 1 57 | else 58 | if line > 1 then 59 | passed = passed + 1 60 | end 61 | end 62 | 63 | alua:close () 64 | txt:close () 65 | print ("") 66 | end 67 | 68 | print ("Results: out of "..total.." tests...",passed.." passed",failed.." failed") 69 | end 70 | } -------------------------------------------------------------------------------- /vs2010/.nuget/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /vs2010/AluminiumLua.Any/AluminiumLua.Any.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 10.0 6 | Debug 7 | AnyCPU 8 | {0226C79B-595B-4FEE-B083-3A2175EB374E} 9 | Library 10 | Properties 11 | AluminiumLua.Any 12 | AluminiumLua.Any 13 | v4.0 14 | Profile2 15 | 512 16 | {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 17 | 18 | 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | TRACE;DEBUG;CROSS 24 | prompt 25 | 4 26 | 27 | 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | Properties\AssemblyInfo.cs 41 | 42 | 43 | Executors\CompilerExecutor.cs 44 | 45 | 46 | Executors\DefaultExecutor.cs 47 | 48 | 49 | Executors\ExpressionTrees\ExpressionCompiler.cs 50 | 51 | 52 | Executors\ExpressionTrees\ExpressionVisitor.cs 53 | 54 | 55 | Executors\IExecutor.cs 56 | 57 | 58 | Executors\InterpreterExecutor.cs 59 | 60 | 61 | Libraries\BasicLibrary.cs 62 | 63 | 64 | Libraries\IoLibrary.cs 65 | 66 | 67 | LuaContext.cs 68 | 69 | 70 | LuaObject.cs 71 | 72 | 73 | LuaParser.cs 74 | 75 | 76 | LuaSettings.cs 77 | 78 | 79 | 80 | 87 | -------------------------------------------------------------------------------- /vs2010/AluminiumLua.WindowsPhone/AluminiumLua.wp8.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 10.0.20506 7 | 2.0 8 | {A2247B3B-97A3-4AD8-962B-02B88D5A9B8F} 9 | {C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 10 | Library 11 | Properties 12 | AluminiumLua 13 | AluminiumLua 14 | WindowsPhone 15 | v8.0 16 | $(TargetFrameworkVersion) 17 | false 18 | true 19 | 11.0 20 | true 21 | 22 | 23 | true 24 | full 25 | false 26 | Bin\Debug 27 | DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE 28 | true 29 | true 30 | prompt 31 | 4 32 | 33 | 34 | pdbonly 35 | true 36 | Bin\Release 37 | TRACE;SILVERLIGHT;WINDOWS_PHONE 38 | true 39 | true 40 | prompt 41 | 4 42 | 43 | 44 | true 45 | full 46 | false 47 | ..\..\nuget\lib\wp8\ 48 | DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE 49 | true 50 | true 51 | prompt 52 | 4 53 | ..\..\nuget\lib\wp8\AluminiumLua.xml 54 | 55 | 56 | pdbonly 57 | true 58 | ..\..\nuget\lib\wp8\ 59 | TRACE;SILVERLIGHT;WINDOWS_PHONE 60 | true 61 | true 62 | prompt 63 | 4 64 | ..\..\nuget\lib\wp8\AluminiumLua.xml 65 | 66 | 67 | true 68 | full 69 | false 70 | Bin\ARM\Debug 71 | DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE 72 | true 73 | true 74 | prompt 75 | 4 76 | 77 | 78 | pdbonly 79 | true 80 | Bin\ARM\Release 81 | TRACE;SILVERLIGHT;WINDOWS_PHONE 82 | true 83 | true 84 | prompt 85 | 4 86 | 87 | 88 | 89 | Properties\AssemblyInfo.cs 90 | 91 | 92 | Executors\CompilerExecutor.cs 93 | 94 | 95 | Executors\DefaultExecutor.cs 96 | 97 | 98 | Executors\ExpressionTrees\ExpressionCompiler.cs 99 | 100 | 101 | Executors\ExpressionTrees\ExpressionVisitor.cs 102 | 103 | 104 | Executors\IExecutor.cs 105 | 106 | 107 | Executors\InterpreterExecutor.cs 108 | 109 | 110 | Libraries\BasicLibrary.cs 111 | 112 | 113 | Libraries\IoLibrary.cs 114 | 115 | 116 | LinkedDictionary.cs 117 | 118 | 119 | LuaContext.cs 120 | 121 | 122 | LuaObject.cs 123 | 124 | 125 | LuaParser.cs 126 | 127 | 128 | LuaSettings.cs 129 | 130 | 131 | 132 | 133 | 134 | 141 | -------------------------------------------------------------------------------- /vs2010/AluminiumLua.WindowsPhone/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | using System.Resources; 5 | 6 | // Les informations générales relatives à un assembly dépendent de 7 | // l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations 8 | // associées à un assembly. 9 | [assembly: AssemblyTitle("AluminiumLua.WindowsPhone")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyProduct("AluminiumLua.WindowsPhone")] 14 | [assembly: AssemblyCopyright("Copyright © 2013")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly 19 | // aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de 20 | // COM, affectez la valeur true à l'attribut ComVisible sur ce type. 21 | [assembly: ComVisible(false)] 22 | 23 | // Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM 24 | [assembly: Guid("a2247b3b-97a3-4ad8-962b-02b88d5a9b8f")] 25 | 26 | // Les informations de version pour un assembly se composent des quatre valeurs suivantes : 27 | // 28 | // Version principale 29 | // Version secondaire 30 | // Numéro de build 31 | // Révision 32 | // 33 | // Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de révision et de build par défaut 34 | // en utilisant '*', comme indiqué ci-dessous : 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | [assembly: NeutralResourcesLanguageAttribute("fr-FR")] 38 | -------------------------------------------------------------------------------- /vs2010/AluminiumLua.wp71/AluminiumLua.wp71.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 10.0.20506 7 | 2.0 8 | {35068574-1278-4BE7-BEE9-BCF56E6FC2F7} 9 | {C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 10 | Library 11 | Properties 12 | AluminiumLua 13 | AluminiumLua 14 | v4.0 15 | $(TargetFrameworkVersion) 16 | WindowsPhone71 17 | Silverlight 18 | false 19 | true 20 | true 21 | 22 | 23 | true 24 | full 25 | false 26 | ..\..\nuget\lib\wp71\ 27 | TRACE;DEBUG;SILVERLIGHT;WINDOWS_PHONE;NET35 28 | true 29 | true 30 | prompt 31 | 4 32 | ..\..\nuget\lib\wp71\AluminiumLua.XML 33 | 34 | 35 | pdbonly 36 | true 37 | ..\..\nuget\lib\wp71\ 38 | TRACE;SILVERLIGHT;WINDOWS_PHONE;NET35 39 | true 40 | true 41 | prompt 42 | 4 43 | ..\..\nuget\lib\wp71\AluminiumLua.XML 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | Properties\AssemblyInfo.cs 56 | 57 | 58 | Executors\CompilerExecutor.cs 59 | 60 | 61 | Executors\DefaultExecutor.cs 62 | 63 | 64 | Executors\ExpressionTrees\ExpressionCompiler.cs 65 | 66 | 67 | Executors\ExpressionTrees\ExpressionVisitor.cs 68 | 69 | 70 | Executors\IExecutor.cs 71 | 72 | 73 | Executors\InterpreterExecutor.cs 74 | 75 | 76 | Libraries\BasicLibrary.cs 77 | 78 | 79 | Libraries\IoLibrary.cs 80 | 81 | 82 | LinkedDictionary.cs 83 | 84 | 85 | LuaContext.cs 86 | 87 | 88 | LuaObject.cs 89 | 90 | 91 | LuaParser.cs 92 | 93 | 94 | LuaSettings.cs 95 | 96 | 97 | 98 | 99 | 100 | 101 | 108 | -------------------------------------------------------------------------------- /vs2010/AluminumLua.Net40/AluminiumLua.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chkn/AluminumLua/0bc5858306cf78708cb4e369075ae76ddb2bbad5/vs2010/AluminumLua.Net40/AluminiumLua.snk -------------------------------------------------------------------------------- /vs2010/AluminumLua.Net40/AluminumLua.Net40.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {BAFD1B0D-16E3-4B17-BCD7-53C5FE3B6AB7} 9 | Library 10 | Properties 11 | AluminumLua 12 | AluminumLua 13 | v4.0 14 | 512 15 | 16 | 17 | 18 | true 19 | full 20 | false 21 | ..\..\nuget\lib\net40\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | ..\..\nuget\lib\net40\AluminumLua.XML 26 | 27 | 28 | pdbonly 29 | true 30 | ..\..\nuget\lib\net40\ 31 | TRACE 32 | prompt 33 | 4 34 | ..\..\nuget\lib\net40\AluminumLua.XML 35 | 36 | 37 | true 38 | 39 | 40 | AluminiumLua.snk 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | Properties\AssemblyInfo.cs 54 | 55 | 56 | Executors\CompilerExecutor.cs 57 | 58 | 59 | Executors\DefaultExecutor.cs 60 | 61 | 62 | Executors\ExpressionTrees\ExpressionCompiler.cs 63 | 64 | 65 | Executors\ExpressionTrees\ExpressionVisitor.cs 66 | 67 | 68 | Executors\IExecutor.cs 69 | 70 | 71 | Executors\InterpreterExecutor.cs 72 | 73 | 74 | Libraries\BasicLibrary.cs 75 | 76 | 77 | Libraries\IoLibrary.cs 78 | 79 | 80 | LinkedDictionary.cs 81 | 82 | 83 | LuaContext.cs 84 | 85 | 86 | LuaObject.cs 87 | 88 | 89 | LuaParser.cs 90 | 91 | 92 | LuaSettings.cs 93 | 94 | 95 | 96 | 97 | 98 | 99 | 106 | -------------------------------------------------------------------------------- /vs2010/AluminumLua.Tests/AluminumLua.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | x86 6 | 8.0.30703 7 | 2.0 8 | {C4E5CA60-0560-464B-B9A4-48F352ACC6F8} 9 | Exe 10 | Properties 11 | AluminumLua.Tests 12 | AluminumLua.Tests 13 | v4.0 14 | Client 15 | 512 16 | 17 | 18 | x86 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | x86 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | ..\packages\NUnit.2.6.2\lib\nunit.framework.dll 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | Always 53 | 54 | 55 | 56 | 57 | 58 | dofile.lua 59 | PreserveNewest 60 | 61 | 62 | functionscopes.lua 63 | PreserveNewest 64 | 65 | 66 | helloworld.lua 67 | PreserveNewest 68 | 69 | 70 | 71 | 72 | 73 | {BAFD1B0D-16E3-4B17-BCD7-53C5FE3B6AB7} 74 | AluminumLua.net40 75 | 76 | 77 | 78 | 85 | -------------------------------------------------------------------------------- /vs2010/AluminumLua.Tests/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace AluminumLua.Tests 7 | { 8 | class Program 9 | { 10 | static void Main(string[] args) 11 | { 12 | TestFile("dofile.lua"); 13 | TestFile("functionscopes.lua"); 14 | TestFile("helloworld.lua"); 15 | TestFile("test.lua"); 16 | Console.ReadKey(); 17 | } 18 | 19 | private static void TestFile(string fileName) 20 | { 21 | var ctx = new AluminumLua.LuaContext(); 22 | ctx.AddBasicLibrary(); 23 | ctx.AddIoLibrary(); 24 | var alua = new AluminumLua.LuaParser(ctx, fileName); 25 | 26 | alua.Parse(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /vs2010/AluminumLua.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("AluminumLua.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("AluminumLua.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("356fb89b-adf6-4d92-9e23-869e4b5c9053")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /vs2010/AluminumLua.Tests/Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | using NUnit.Framework; 5 | 6 | namespace AluminumLua.Tests 7 | { 8 | [TestFixture] 9 | public class Tests 10 | { 11 | [Test] 12 | public void DoFileTest() 13 | { 14 | LuaParser parser; 15 | 16 | var context = new LuaContext(); 17 | context.AddBasicLibrary(); 18 | context.AddIoLibrary(); 19 | 20 | parser = new LuaParser(context, "dofile.lua"); 21 | parser.Parse(); 22 | } 23 | 24 | [Test] 25 | public void FunctionScopesTest() 26 | { 27 | LuaParser parser; 28 | 29 | var context = new LuaContext(); 30 | context.AddBasicLibrary(); 31 | context.AddIoLibrary(); 32 | 33 | parser = new LuaParser(context, "functionscopes.lua"); 34 | parser.Parse(); 35 | } 36 | 37 | [Test] 38 | public void HelloWorldTest() 39 | { 40 | LuaParser parser; 41 | 42 | var context = new LuaContext(); 43 | context.AddBasicLibrary(); 44 | context.AddIoLibrary(); 45 | 46 | parser = new LuaParser(context, "helloworld.lua"); 47 | parser.Parse(); 48 | } 49 | 50 | [Test] 51 | public void MethodBinding() 52 | { 53 | LuaParser parser; 54 | 55 | var context = new LuaContext(); 56 | context.AddBasicLibrary(); 57 | context.AddIoLibrary(); 58 | double res = 0; 59 | var func = (Func)((a) => 60 | { 61 | res = a; 62 | return a + 1; 63 | }); 64 | context.SetGlobal("test", LuaObject.FromDelegate(func)); 65 | parser = new LuaParser(context, new StringReader("test(123)")); 66 | parser.Parse(); 67 | Assert.AreEqual(123.0,res); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /vs2010/AluminumLua.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /vs2010/AluminumLua.Tests/test.lua: -------------------------------------------------------------------------------- 1 | function test() 2 | if (2 > 1) and (2 ~= 1) then print "yes" else print "no!" end 3 | if (2 < 1) and (2 ~= 1) then print "yes" else print "no!" end 4 | if (1 > 1) or (2 ~= 1) then print "yes" else print "no!" end 5 | if (1 > 1) or (2 == 1) then print "yes" else print "no!" end 6 | if (2 > 1) or (2 ~= 1) then print "yes" else print "no!" end 7 | end 8 | test() -------------------------------------------------------------------------------- /vs2010/AluminumLua.sl5/AluminiumLua.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chkn/AluminumLua/0bc5858306cf78708cb4e369075ae76ddb2bbad5/vs2010/AluminumLua.sl5/AluminiumLua.snk -------------------------------------------------------------------------------- /vs2010/AluminumLua.sl5/AluminumLua.sl5.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.50727 7 | 2.0 8 | {1B899588-6863-4061-83B5-C6B702B3377E} 9 | {A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 10 | Library 11 | Properties 12 | AluminumLua 13 | AluminumLua 14 | Silverlight 15 | v5.0 16 | $(TargetFrameworkVersion) 17 | false 18 | true 19 | true 20 | 21 | 24 | 25 | v3.5 26 | 27 | 28 | true 29 | full 30 | false 31 | ..\..\nuget\lib\sl5\ 32 | DEBUG;TRACE;SILVERLIGHT 33 | true 34 | true 35 | prompt 36 | 4 37 | ..\..\nuget\lib\sl5\AluminumLua.xml 38 | 39 | 40 | pdbonly 41 | true 42 | ..\..\nuget\lib\sl5\ 43 | TRACE;SILVERLIGHT 44 | true 45 | true 46 | prompt 47 | 4 48 | ..\..\nuget\lib\sl5\AluminumLua.xml 49 | 50 | 51 | true 52 | 53 | 54 | AluminiumLua.snk 55 | 56 | 57 | 58 | 59 | 60 | 61 | $(TargetFrameworkDirectory)System.Core.dll 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | Properties\AssemblyInfo.cs 70 | 71 | 72 | Executors\CompilerExecutor.cs 73 | 74 | 75 | Executors\DefaultExecutor.cs 76 | 77 | 78 | Executors\ExpressionTrees\ExpressionCompiler.cs 79 | 80 | 81 | Executors\ExpressionTrees\ExpressionVisitor.cs 82 | 83 | 84 | Executors\IExecutor.cs 85 | 86 | 87 | Executors\InterpreterExecutor.cs 88 | 89 | 90 | Libraries\BasicLibrary.cs 91 | 92 | 93 | Libraries\IoLibrary.cs 94 | 95 | 96 | LinkedDictionary.cs 97 | 98 | 99 | LuaContext.cs 100 | 101 | 102 | LuaObject.cs 103 | 104 | 105 | LuaParser.cs 106 | 107 | 108 | LuaSettings.cs 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 129 | -------------------------------------------------------------------------------- /vs2010/AluminumLua.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AluminumLua.net40", "AluminumLua.Net40\AluminumLua.net40.csproj", "{BAFD1B0D-16E3-4B17-BCD7-53C5FE3B6AB7}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AluminumLua.Tests", "AluminumLua.Tests\AluminumLua.Tests.csproj", "{C4E5CA60-0560-464B-B9A4-48F352ACC6F8}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{75FFDD76-0A3D-4E52-9129-B9E3E6A78D2C}" 9 | ProjectSection(SolutionItems) = preProject 10 | .nuget\packages.config = .nuget\packages.config 11 | EndProjectSection 12 | EndProject 13 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AluminiumLua.wp8", "AluminiumLua.WindowsPhone\AluminiumLua.wp8.csproj", "{A2247B3B-97A3-4AD8-962B-02B88D5A9B8F}" 14 | EndProject 15 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AluminumLua.sl5", "AluminumLua.sl5\AluminumLua.sl5.csproj", "{1B899588-6863-4061-83B5-C6B702B3377E}" 16 | EndProject 17 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AluminiumLua.wp71", "AluminiumLua.wp71\AluminiumLua.wp71.csproj", "{35068574-1278-4BE7-BEE9-BCF56E6FC2F7}" 18 | EndProject 19 | Global 20 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 21 | Debug|Any CPU = Debug|Any CPU 22 | Debug|ARM = Debug|ARM 23 | Debug|Mixed Platforms = Debug|Mixed Platforms 24 | Debug|x86 = Debug|x86 25 | Release|Any CPU = Release|Any CPU 26 | Release|ARM = Release|ARM 27 | Release|Mixed Platforms = Release|Mixed Platforms 28 | Release|x86 = Release|x86 29 | EndGlobalSection 30 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 31 | {BAFD1B0D-16E3-4B17-BCD7-53C5FE3B6AB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 32 | {BAFD1B0D-16E3-4B17-BCD7-53C5FE3B6AB7}.Debug|Any CPU.Build.0 = Debug|Any CPU 33 | {BAFD1B0D-16E3-4B17-BCD7-53C5FE3B6AB7}.Debug|ARM.ActiveCfg = Debug|Any CPU 34 | {BAFD1B0D-16E3-4B17-BCD7-53C5FE3B6AB7}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 35 | {BAFD1B0D-16E3-4B17-BCD7-53C5FE3B6AB7}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 36 | {BAFD1B0D-16E3-4B17-BCD7-53C5FE3B6AB7}.Debug|x86.ActiveCfg = Debug|Any CPU 37 | {BAFD1B0D-16E3-4B17-BCD7-53C5FE3B6AB7}.Release|Any CPU.ActiveCfg = Release|Any CPU 38 | {BAFD1B0D-16E3-4B17-BCD7-53C5FE3B6AB7}.Release|Any CPU.Build.0 = Release|Any CPU 39 | {BAFD1B0D-16E3-4B17-BCD7-53C5FE3B6AB7}.Release|ARM.ActiveCfg = Release|Any CPU 40 | {BAFD1B0D-16E3-4B17-BCD7-53C5FE3B6AB7}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 41 | {BAFD1B0D-16E3-4B17-BCD7-53C5FE3B6AB7}.Release|Mixed Platforms.Build.0 = Release|Any CPU 42 | {BAFD1B0D-16E3-4B17-BCD7-53C5FE3B6AB7}.Release|x86.ActiveCfg = Release|Any CPU 43 | {C4E5CA60-0560-464B-B9A4-48F352ACC6F8}.Debug|Any CPU.ActiveCfg = Debug|x86 44 | {C4E5CA60-0560-464B-B9A4-48F352ACC6F8}.Debug|ARM.ActiveCfg = Debug|x86 45 | {C4E5CA60-0560-464B-B9A4-48F352ACC6F8}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 46 | {C4E5CA60-0560-464B-B9A4-48F352ACC6F8}.Debug|Mixed Platforms.Build.0 = Debug|x86 47 | {C4E5CA60-0560-464B-B9A4-48F352ACC6F8}.Debug|x86.ActiveCfg = Debug|x86 48 | {C4E5CA60-0560-464B-B9A4-48F352ACC6F8}.Debug|x86.Build.0 = Debug|x86 49 | {C4E5CA60-0560-464B-B9A4-48F352ACC6F8}.Release|Any CPU.ActiveCfg = Release|x86 50 | {C4E5CA60-0560-464B-B9A4-48F352ACC6F8}.Release|ARM.ActiveCfg = Release|x86 51 | {C4E5CA60-0560-464B-B9A4-48F352ACC6F8}.Release|Mixed Platforms.ActiveCfg = Release|x86 52 | {C4E5CA60-0560-464B-B9A4-48F352ACC6F8}.Release|Mixed Platforms.Build.0 = Release|x86 53 | {C4E5CA60-0560-464B-B9A4-48F352ACC6F8}.Release|x86.ActiveCfg = Release|x86 54 | {C4E5CA60-0560-464B-B9A4-48F352ACC6F8}.Release|x86.Build.0 = Release|x86 55 | {A2247B3B-97A3-4AD8-962B-02B88D5A9B8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 56 | {A2247B3B-97A3-4AD8-962B-02B88D5A9B8F}.Debug|Any CPU.Build.0 = Debug|Any CPU 57 | {A2247B3B-97A3-4AD8-962B-02B88D5A9B8F}.Debug|ARM.ActiveCfg = Debug|ARM 58 | {A2247B3B-97A3-4AD8-962B-02B88D5A9B8F}.Debug|ARM.Build.0 = Debug|ARM 59 | {A2247B3B-97A3-4AD8-962B-02B88D5A9B8F}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 60 | {A2247B3B-97A3-4AD8-962B-02B88D5A9B8F}.Debug|Mixed Platforms.Build.0 = Debug|x86 61 | {A2247B3B-97A3-4AD8-962B-02B88D5A9B8F}.Debug|x86.ActiveCfg = Debug|x86 62 | {A2247B3B-97A3-4AD8-962B-02B88D5A9B8F}.Debug|x86.Build.0 = Debug|x86 63 | {A2247B3B-97A3-4AD8-962B-02B88D5A9B8F}.Release|Any CPU.ActiveCfg = Release|Any CPU 64 | {A2247B3B-97A3-4AD8-962B-02B88D5A9B8F}.Release|Any CPU.Build.0 = Release|Any CPU 65 | {A2247B3B-97A3-4AD8-962B-02B88D5A9B8F}.Release|ARM.ActiveCfg = Release|ARM 66 | {A2247B3B-97A3-4AD8-962B-02B88D5A9B8F}.Release|ARM.Build.0 = Release|ARM 67 | {A2247B3B-97A3-4AD8-962B-02B88D5A9B8F}.Release|Mixed Platforms.ActiveCfg = Release|x86 68 | {A2247B3B-97A3-4AD8-962B-02B88D5A9B8F}.Release|Mixed Platforms.Build.0 = Release|x86 69 | {A2247B3B-97A3-4AD8-962B-02B88D5A9B8F}.Release|x86.ActiveCfg = Release|x86 70 | {A2247B3B-97A3-4AD8-962B-02B88D5A9B8F}.Release|x86.Build.0 = Release|x86 71 | {1B899588-6863-4061-83B5-C6B702B3377E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 72 | {1B899588-6863-4061-83B5-C6B702B3377E}.Debug|Any CPU.Build.0 = Debug|Any CPU 73 | {1B899588-6863-4061-83B5-C6B702B3377E}.Debug|ARM.ActiveCfg = Debug|Any CPU 74 | {1B899588-6863-4061-83B5-C6B702B3377E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 75 | {1B899588-6863-4061-83B5-C6B702B3377E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 76 | {1B899588-6863-4061-83B5-C6B702B3377E}.Debug|x86.ActiveCfg = Debug|Any CPU 77 | {1B899588-6863-4061-83B5-C6B702B3377E}.Release|Any CPU.ActiveCfg = Release|Any CPU 78 | {1B899588-6863-4061-83B5-C6B702B3377E}.Release|Any CPU.Build.0 = Release|Any CPU 79 | {1B899588-6863-4061-83B5-C6B702B3377E}.Release|ARM.ActiveCfg = Release|Any CPU 80 | {1B899588-6863-4061-83B5-C6B702B3377E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 81 | {1B899588-6863-4061-83B5-C6B702B3377E}.Release|Mixed Platforms.Build.0 = Release|Any CPU 82 | {1B899588-6863-4061-83B5-C6B702B3377E}.Release|x86.ActiveCfg = Release|Any CPU 83 | {35068574-1278-4BE7-BEE9-BCF56E6FC2F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 84 | {35068574-1278-4BE7-BEE9-BCF56E6FC2F7}.Debug|Any CPU.Build.0 = Debug|Any CPU 85 | {35068574-1278-4BE7-BEE9-BCF56E6FC2F7}.Debug|ARM.ActiveCfg = Debug|Any CPU 86 | {35068574-1278-4BE7-BEE9-BCF56E6FC2F7}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 87 | {35068574-1278-4BE7-BEE9-BCF56E6FC2F7}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 88 | {35068574-1278-4BE7-BEE9-BCF56E6FC2F7}.Debug|x86.ActiveCfg = Debug|Any CPU 89 | {35068574-1278-4BE7-BEE9-BCF56E6FC2F7}.Release|Any CPU.ActiveCfg = Release|Any CPU 90 | {35068574-1278-4BE7-BEE9-BCF56E6FC2F7}.Release|Any CPU.Build.0 = Release|Any CPU 91 | {35068574-1278-4BE7-BEE9-BCF56E6FC2F7}.Release|ARM.ActiveCfg = Release|Any CPU 92 | {35068574-1278-4BE7-BEE9-BCF56E6FC2F7}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 93 | {35068574-1278-4BE7-BEE9-BCF56E6FC2F7}.Release|Mixed Platforms.Build.0 = Release|Any CPU 94 | {35068574-1278-4BE7-BEE9-BCF56E6FC2F7}.Release|x86.ActiveCfg = Release|Any CPU 95 | EndGlobalSection 96 | GlobalSection(SolutionProperties) = preSolution 97 | HideSolutionNode = FALSE 98 | EndGlobalSection 99 | EndGlobal 100 | -------------------------------------------------------------------------------- /vs2010/packages/repositories.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | --------------------------------------------------------------------------------