pjc0247 / SlowSharp

C# interpreter written in C#
MIT License
130 stars 15 forks source link

SemanticViolationException: No matching override for `Button` #4

Open friuns2 opened 2 years ago

friuns2 commented 2 years ago

Hi i'm working on modding tool using slowsharp https://github.com/friuns2/LuaMod/tree/SharpMod

if i type GUILayout.Button("test"); it throws exception, can you help?

SemanticViolationException: No matching override for `Button`
Slowsharp.Runner.RunInvocation (Microsoft.CodeAnalysis.CSharp.Syntax.InvocationExpressionSyntax node) (at <2cd81ad168544a2391dd8ded9b2f4f87>:0)
Slowsharp.Runner.RunExpression (Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax node) (at <2cd81ad168544a2391dd8ded9b2f4f87>:0)
Slowsharp.Runner.RunIf (Microsoft.CodeAnalysis.CSharp.Syntax.IfStatementSyntax node) (at <2cd81ad168544a2391dd8ded9b2f4f87>:0)
Slowsharp.Runner.RunAsExecution (Microsoft.CodeAnalysis.SyntaxNode node) (at <2cd81ad168544a2391dd8ded9b2f4f87>:0)
Slowsharp.Runner.Run (Microsoft.CodeAnalysis.SyntaxNode node) (at <2cd81ad168544a2391dd8ded9b2f4f87>:0)
Slowsharp.Runner.RunBlock (Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax node, Slowsharp.VarFrame vf, System.Int32 pc) (at <2cd81ad168544a2391dd8ded9b2f4f87>:0)
Slowsharp.Runner.RunMethod (Slowsharp.SSMethodInfo method, Slowsharp.HybInstance[] args) (at <2cd81ad168544a2391dd8ded9b2f4f87>:0)
Slowsharp.Runner.RunMethod (Slowsharp.HybInstance _this, Slowsharp.SSMethodInfo method, Slowsharp.HybInstance[] args) (at <2cd81ad168544a2391dd8ded9b2f4f87>:0)
Slowsharp.Invokable.Invoke (Slowsharp.HybInstance _this, Slowsharp.HybInstance[] args, System.Boolean hasRefOrOut) (at <2cd81ad168544a2391dd8ded9b2f4f87>:0)
Slowsharp.SSMethodInfo.Invoke (Slowsharp.HybInstance _this, Slowsharp.HybInstance[] args) (at <2cd81ad168544a2391dd8ded9b2f4f87>:0)
MethodPool.Execute1 () (at Assets/Scripts/SharpMod/MethodPool.cs:34)
friuns2 commented 2 years ago

CScript.Run("using UnityEngine; class Test{ void Main(){GUILayout.Button(\"test\")}}");

ah looks like it cannot handle params 

public static bool Button(string text, params GUILayoutOption[] options)

pjc0247 commented 2 years ago

Sorry for inconvenience. SlowSharp does not support full C# syntax. seems like there are missing implementation of params as you said.

https://github.com/Ourpalm/ILRuntime

what about take a look of this project. it's actively maintained til now.

friuns2 commented 2 years ago

Thanks i know about it, but it cant compile c# code at runtime. I'm very happy with this project so far works flowlesly :)

pjc0247 commented 2 years ago

@friuns2 you can execute .cs file using ILRuntime. https://stackoverflow.com/questions/32769630/how-to-compile-a-c-sharp-file-with-roslyn-programmatically .cs -> roslyn -> .dll -> ILRuntime.

or you may want to take a look this asset https://assetstore.unity.com/packages/tools/cs-script-for-unity-23510 (can execute 100% of C# syntax. the only problem is JIT based scripting engine won't work on iOS or WebAssembly)

friuns2 commented 2 years ago

I'm building for android and it need il2cpp for 64bit

.cs -> roslyn -> .dll -> ILRuntime.

That could work but have to copy all dlls to project resources

friuns2 commented 2 years ago

also in ILRuntime is no easy way to override class, have to create Adaptor, but your CScript.Override works without any additional code