Skip to content

Commit

Permalink
Merge branch 'feature/vscode_debug'
Browse files Browse the repository at this point in the history
  • Loading branch information
xanathar committed Oct 7, 2016
2 parents 22972f1 + 50facb4 commit 45ca7a3
Show file tree
Hide file tree
Showing 363 changed files with 39,628 additions and 43 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Features:
* 99% compatible with Lua 5.2 (with the only unsupported feature being weak tables support)
* Support for metalua style anonymous functions (lambda-style)
* Easy to use API
* Source based remote **debugger** accessible with a web browser and Flash (PCL targets not supported)
* **Debugger** support for Visual Studio Code (PCL targets not supported)
* Remote debugger accessible with a web browser and Flash (PCL targets not supported)
* Runs on .NET 3.5, .NET 4.x, Mono, Xamarin and Unity3D
* Runs on Ahead-of-time platforms like iOS
* Runs on IL2CPP converted code
Expand All @@ -21,6 +22,7 @@ Features:
* Support for the complete Lua standard library with very few exceptions (mostly located on the 'debug' module) and a few extensions (in the string library, mostly)
* Async methods for .NET 4.x targets
* Supports dumping/loading bytecode for obfuscation and quicker parsing at runtime
* An embedded JSON parser (with no dependencies) to convert between JSON and Lua tables
* Easy opt-out of Lua standard library modules to sandbox what scripts can access
* Easy to use error handling (script errors are exceptions)
* Support for coroutines, including invocation of coroutines as C# iterators
Expand Down
9 changes: 9 additions & 0 deletions src/DevTools/MoonSharp.VmDebugger/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,5 +441,14 @@ private void btnOpenTest_Click(object sender, EventArgs e)
{

}

public void SetDebugService(DebugService debugService)
{
}

public DebuggerCaps GetDebuggerCaps()
{
return DebuggerCaps.CanDebugByteCode;
}
}
}
8 changes: 8 additions & 0 deletions src/DevTools/SynchProjects/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,17 @@ static void Main(string[] args)
const string DEBUGGER_SUBPROJECTS_PATHS = @"{BASEPATH}\MoonSharp.RemoteDebugger\_Projects\MoonSharp.RemoteDebugger.{0}\MoonSharp.RemoteDebugger.{0}.csproj";
const string DEBUGGER_PATH_PREFIX = @"..\..\";

const string VSCODEDEBUGGER_PROJECT = @"{BASEPATH}\MoonSharp.VsCodeDebugger\MoonSharp.VsCodeDebugger.net35-client.csproj";
const string VSCODEDEBUGGER_SUBPROJECTS_PATHS = @"{BASEPATH}\MoonSharp.VsCodeDebugger\_Projects\MoonSharp.VsCodeDebugger.{0}\MoonSharp.VsCodeDebugger.{0}.csproj";
const string VSCODEDEBUGGER_PATH_PREFIX = @"..\..\";

const string TESTS_PROJECT = @"{BASEPATH}\MoonSharp.Interpreter.Tests\MoonSharp.Interpreter.Tests.net35-client.csproj";
const string TESTS_SUBPROJECTS_PATHS = @"{BASEPATH}\MoonSharp.Interpreter.Tests\_Projects\MoonSharp.Interpreter.Tests.{0}\MoonSharp.Interpreter.Tests.{0}.csproj";
const string TESTS_PATH_PREFIX = @"..\..\";

string[] INTERPRETER_PLATFORMS = new string[] { "net40-client", "portable40" };
string[] DEBUGGER_PLATFORMS = new string[] { "net40-client" };
string[] VSCODEDEBUGGER_PLATFORMS = new string[] { "net40-client" };
string[] TESTS_PLATFORMS = new string[] { "net40-client", "portable40", "Embeddable.portable40" };

CalcBasePath();
Expand All @@ -123,6 +128,9 @@ static void Main(string[] args)
foreach (string platform in DEBUGGER_PLATFORMS)
CopyCompileFilesAsLinks(platform, DEBUGGER_PROJECT, DEBUGGER_SUBPROJECTS_PATHS, DEBUGGER_PATH_PREFIX);

foreach (string platform in VSCODEDEBUGGER_PLATFORMS)
CopyCompileFilesAsLinks(platform, VSCODEDEBUGGER_PROJECT, VSCODEDEBUGGER_SUBPROJECTS_PATHS, VSCODEDEBUGGER_PATH_PREFIX);

foreach (string platform in TESTS_PLATFORMS)
CopyCompileFilesAsLinks(platform, TESTS_PROJECT, TESTS_SUBPROJECTS_PATHS, TESTS_PATH_PREFIX);

Expand Down
53 changes: 53 additions & 0 deletions src/DevTools/VsCodeDebugger_Testbed/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using MoonSharp.Interpreter;
using MoonSharp.VsCodeDebugger;
using MoonSharp.VsCodeDebugger.SDK;

namespace VsCodeDebugger_Testbed
{
class Program
{
const int DEFAULT_PORT = 41912;

public static void Main(string[] argv)
{
Script script = new Script();
MoonSharpVsCodeDebugServer server = new MoonSharpVsCodeDebugServer(script, DEFAULT_PORT);

script.AttachDebugger(server.GetDebugger());

script.DoFile(@"Z:/HDD/temp/lua/fact.lua");

Closure func = script.Globals.Get("run").Function;

server.Start();

Console.WriteLine("READY.");

while (true)//(Console.ReadKey().Key != ConsoleKey.Escape)
{
try
{
var val = func.Call(5);
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine(val.Number);
System.Threading.Thread.Sleep(5000);
}
catch (InterpreterException ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(ex.DecoratedMessage);
}
}
}



}
}
36 changes: 36 additions & 0 deletions src/DevTools/VsCodeDebugger_Testbed/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("VsCodeDebugger_Testbed")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VsCodeDebugger_Testbed")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("d17dd647-76cf-4d87-bdf7-75e1704e8783")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
64 changes: 64 additions & 0 deletions src/DevTools/VsCodeDebugger_Testbed/VsCodeDebugger_Testbed.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D17DD647-76CF-4D87-BDF7-75E1704E8783}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>VsCodeDebugger_Testbed</RootNamespace>
<AssemblyName>VsCodeDebugger_Testbed</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\MoonSharp.Interpreter\MoonSharp.Interpreter.net35-client.csproj">
<Project>{91ea9b9d-fe03-4273-bdaf-8ad42ede1e59}</Project>
<Name>MoonSharp.Interpreter.net35-client</Name>
</ProjectReference>
<ProjectReference Include="..\..\MoonSharp.VsCodeDebugger\MoonSharp.VsCodeDebugger.net35-client.csproj">
<Project>{eb7d4595-299f-489b-90ac-55066a4675f9}</Project>
<Name>MoonSharp.VsCodeDebugger.net35-client</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
136 changes: 136 additions & 0 deletions src/MoonSharp.Interpreter.Tests/EndToEnd/JsonSerializationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MoonSharp.Interpreter;
using MoonSharp.Interpreter.Serialization.Json;
using NUnit.Framework;


namespace MoonSharp.Interpreter.Tests.EndToEnd
{
[TestFixture]
public class JsonSerializationTests
{
void AssertTableValues(Table t)
{
Assert.AreEqual(DataType.Number, t.Get("aNumber").Type);
Assert.AreEqual(1, t.Get("aNumber").Number);

Assert.AreEqual(DataType.String, t.Get("aString").Type);
Assert.AreEqual("2", t.Get("aString").String);

Assert.AreEqual(DataType.Table, t.Get("anObject").Type);
Assert.AreEqual(DataType.Table, t.Get("anArray").Type);

Table o = t.Get("anObject").Table;

Assert.AreEqual(DataType.Number, o.Get("aNumber").Type);
Assert.AreEqual(3, o.Get("aNumber").Number);

Assert.AreEqual(DataType.String, o.Get("aString").Type);
Assert.AreEqual("4", o.Get("aString").String);

Table a = t.Get("anArray").Table;

// 'anArray' : [ 5, '6', true, null, { 'aNumber' : 7, 'aString' : '8' } ]

Assert.AreEqual(DataType.Number, a.Get(1).Type);
Assert.AreEqual(5, a.Get(1).Number);

Assert.AreEqual(DataType.String, a.Get(2).Type);
Assert.AreEqual("6", a.Get(2).String);

Assert.AreEqual(DataType.Boolean, a.Get(3).Type);
Assert.IsTrue(a.Get(3).Boolean);

Assert.AreEqual(DataType.Boolean, a.Get(3).Type);
Assert.IsTrue(a.Get(3).Boolean);

Assert.AreEqual(DataType.UserData, a.Get(4).Type);
Assert.IsTrue(JsonNull.IsJsonNull(a.Get(4)));

Assert.AreEqual(DataType.Table, a.Get(5).Type);
Table s = a.Get(5).Table;

Assert.AreEqual(DataType.Number, s.Get("aNumber").Type);
Assert.AreEqual(7, s.Get("aNumber").Number);

Assert.AreEqual(DataType.String, s.Get("aString").Type);
Assert.AreEqual("8", s.Get("aString").String);
}


[Test]
public void JsonDeserialization()
{
string json = @"{
'aNumber' : 1,
'aString' : '2',
'anObject' : { 'aNumber' : 3, 'aString' : '4' },
'anArray' : [ 5, '6', true, null, { 'aNumber' : 7, 'aString' : '8' } ]
}
".Replace('\'', '\"');

Table t = JsonTableConverter.JsonToTable(json);
AssertTableValues(t);
}

[Test]
public void JsonSerialization()
{
string json = @"{
'aNumber' : 1,
'aString' : '2',
'anObject' : { 'aNumber' : 3, 'aString' : '4' },
'anArray' : [ 5, '6', true, null, { 'aNumber' : 7, 'aString' : '8' } ]
}
".Replace('\'', '\"');

Table t1 = JsonTableConverter.JsonToTable(json);

string json2 = JsonTableConverter.TableToJson(t1);

Table t = JsonTableConverter.JsonToTable(json2);

AssertTableValues(t);
}


[Test]
public void JsonObjectSerialization()
{
object o = new
{
aNumber = 1,
aString = "2",
anObject = new
{
aNumber = 3,
aString = "4"
},
anArray = new object[]
{
5,
"6",
true,
null,
new
{
aNumber = 7,
aString = "8"
}
}
};


string json = JsonTableConverter.ObjectToJson(o);

Table t = JsonTableConverter.JsonToTable(json);

AssertTableValues(t);
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
<Compile Include="EndToEnd\DynamicTests.cs" />
<Compile Include="EndToEnd\ErrorHandlingTests.cs" />
<Compile Include="EndToEnd\GotoTests.cs" />
<Compile Include="EndToEnd\JsonSerializationTests.cs" />
<Compile Include="EndToEnd\LuaTestSuiteExtract.cs" />
<Compile Include="EndToEnd\MetatableTests.cs">
<SubType>Code</SubType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@
<Compile Include="..\..\EndToEnd\GotoTests.cs">
<Link>GotoTests.cs</Link>
</Compile>
<Compile Include="..\..\EndToEnd\JsonSerializationTests.cs">
<Link>JsonSerializationTests.cs</Link>
</Compile>
<Compile Include="..\..\EndToEnd\LuaTestSuiteExtract.cs">
<Link>LuaTestSuiteExtract.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
<Compile Include="..\..\EndToEnd\GotoTests.cs">
<Link>GotoTests.cs</Link>
</Compile>
<Compile Include="..\..\EndToEnd\JsonSerializationTests.cs">
<Link>JsonSerializationTests.cs</Link>
</Compile>
<Compile Include="..\..\EndToEnd\LuaTestSuiteExtract.cs">
<Link>LuaTestSuiteExtract.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
<Compile Include="..\..\EndToEnd\GotoTests.cs">
<Link>GotoTests.cs</Link>
</Compile>
<Compile Include="..\..\EndToEnd\JsonSerializationTests.cs">
<Link>JsonSerializationTests.cs</Link>
</Compile>
<Compile Include="..\..\EndToEnd\LuaTestSuiteExtract.cs">
<Link>LuaTestSuiteExtract.cs</Link>
</Compile>
Expand Down
Loading

0 comments on commit 45ca7a3

Please sign in to comment.