Code Monkey home page Code Monkey logo

moonsharp-devs / moonsharp Goto Github PK

View Code? Open in Web Editor NEW
1.4K 90.0 210.0 71.28 MB

An interpreter for the Lua language, written entirely in C# for the .NET, Mono, Xamarin and Unity3D platforms, including handy remote debugger facilities.

Home Page: http://www.moonsharp.org

License: Other

C# 82.61% Lua 15.07% HTML 0.28% JavaScript 1.17% ActionScript 0.11% CSS 0.41% Makefile 0.23% Shell 0.04% Batchfile 0.01% Smalltalk 0.01% ShaderLab 0.02% TypeScript 0.05%
moonsharp mono debugger interpreter c-sharp unity3d lua xamarin

moonsharp's People

Contributors

applejag avatar atom0s avatar benjamin-dobell avatar bplu4t2f avatar callumdev avatar dorisugita avatar ebeem avatar fgretief avatar fumobox avatar imerr avatar ixjf avatar jagt avatar jernejk avatar johnwordsworth avatar limpingninja avatar matija-hustic avatar nullshock78 avatar seijikun avatar silv3rpro avatar wledfor2 avatar xanathar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

moonsharp's Issues

Simplify method marshalling

  • Improve CallbackFunction.FromMethodInfo
  • Make StandardUserDataMethodDescriptor public
  • Make StandardUserDataPropertyDecriptor public

Improve TypeDescriptors

  • Support custom descriptors
  • Support different policies for unregistered types
  • Support overloads in some way
  • Support automatic case conversion as an option

Port Diarmuid userdata registration helper

public static void InitUserData()
{
var userDataTypes =
from t in Assembly.GetExecutingAssembly().GetTypes()
let attributes = t.GetCustomAttributes(typeof(MoonSharpUserDataAttribute), true)
where attributes != null && attributes.Length > 0
select t;

foreach (var userDataType in userDataTypes)
{
UserData.RegisterType(userDataType);
}
}

Assigning nil to a table field should delete it

In Lua 5.2, this code:

function showTable(t)
    for i, j in pairs(t) do
        print(j)
    end
end

tb = {}
tb["id"] = 3

print("Before:")
showTable(tb)

tb["id"] = nil

print("After:")
showTable(tb)
print("End")

outputs this:

Before:
3
After:
End

while in Moonsharp it outputs:

Before:
3
After:
nil
End

In my script I want to add and remove a lot of values in a table so I always end up with a huge table filled with nil values, which is useless. table.remove(tbl, pos) don't work because pos must be an integer of the position, and can't be a string for the key like here with the associative array.

MoonSharp fails a simple test script that uses table functions.

The script is TableIntGet.lua, a rather trivial one:

local t = {};
-- C-Lua schneller
for i = 1,10000,1 do
    t[i] = i;
end;

-- interessant! C-Lua ziemlich lahm
for i = 1,100,1 do
    table.remove(t, i + 1000);
end;
for i = 1,100,1 do
    table.insert(t, i + 1000, 1);
end;

-- C-Lua schneller
local sum = 0;
for i = 1,10000,1 do
    sum = sum + t[i];
end;

The exception is:

MoonSharp.Interpreter.ScriptRuntimeException: attempt to perform arithmetic on a nil value
   at MoonSharp.Interpreter.Execution.VM.Processor.ExecAdd(Instruction i, Int32 instructionPtr) in c:\git\moonsharp\src\MoonSharp.Interpreter\Execution\VM\Processor\Processor_InstructionLoop.cs:line 806
   at MoonSharp.Interpreter.Execution.VM.Processor.Processing_Loop(Int32 instructionPtr) in c:\git\moonsharp\src\MoonSharp.Interpreter\Execution\VM\Processor\Processor_InstructionLoop.cs:line 283
   at MoonSharp.Interpreter.Execution.VM.Processor.Call(DynValue function, DynValue[] args) in c:\git\moonsharp\src\MoonSharp.Interpreter\Execution\VM\Processor\Processor.cs:line 61
   at MoonSharp.Interpreter.Script.Call(DynValue function) in c:\git\moonsharp\src\MoonSharp.Interpreter\Script.cs:line 269
   at MoonSharp.Interpreter.Script.DoString(String code, Table globalContext) in c:\git\moonsharp\src\MoonSharp.Interpreter\Script.cs:line 202

The script is executed via a simple DoString(). Both LuaInterface and NeoLua handle it without any errors.

Nuget package forces Antlr4.Runtime.net35.dll on all frameworks

Currently Antlr4 runtime is not a dependency in the nuget package, but forced as a reference. This is intentional, otherwise the nuget package wouldn't work with frameworks 4.x.

The side effect, however, is that any project which uses Moon# and Antlr4 for other scripting uses, has a conflict.

8-queens problem crashes the interpreter

8 queens crashes:

N = 8

board = {}
for i = 1, N do
    board[i] = {}
    for j = 1, N do
    board[i][j] = false
    end
end

function Allowed( x, y )
    for i = 1, x-1 do
    if ( board[i][y] ) or ( i <= y and board[x-i][y-i] ) or ( y+i <= N and board[x-i][y+i] ) then 
        return false 
    end
    end     
    return true
end

function Find_Solution( x )
    for y = 1, N do
    if Allowed( x, y ) then 
        board[x][y] = true 
        if x == N or Find_Solution( x+1 ) then
        return true
        end
        board[x][y] = false          
    end     
    end
    return false
end

if Find_Solution( 1 ) then
    for i = 1, N do
    for j = 1, N do
        if board[i][j] then 
        print( 'Q' )
        else 
        print( 'x' )
        end
    end
    print( '|' )
    end
else
    print( 'NO!' )
end

Coroutine.resume does not handle errors gracefully.

This crashes:

    public static void Main()
    {
        string code = @"
            function a()
                callback(b)
            end

            function b()
                coroutine.yield();
            end                     

            c = coroutine.create(a);

            coroutine.resume(c);        
            ";

        // Load the code and get the returned function
        Script script = new Script();

        script.Globals["callback"] = DynValue.NewCallback(
            (ctx, args) => args[0].Function.Call()
            );

        DynValue function = script.DoString(code);

        // This raises an error of "attempt to yield from outside a coroutine"
        function.Function.Call();


        Console.ReadKey();
    }

Revise Exception ctor overloads

Revise Exception ctors, because the string can potentially contain tokens interpreted by string.Format.. see for example InterpreterException ctor.

Void management is not exactly as Lua does

function x() end
print(x(), 3, x(), 4, x(), x())
Lua : nil 3 nil 4 nil
MoonSharp : nil 3 nil 4

However, for default params it's helpful the way MoonSharp does.

Also, voids must be checked for compatibility with varargs.

Threading check not working properly

  • Processor.LeaveProcessor must reset m_OwningThreadID.
  • Have an option to disable the test anyway, as there are corner cases which are legal and yet would trigger the exception (e.g. switching thread and back inside a clr callback).

xpcall is currently a dumb wrapper over pcall

xpcall is a dumb wrapper over pcall.
A "serious" implementation of xpcall requires the debug lib to be useful, which is not portable to moon#.
We might want to just have xpcall spit tracebacks and pcall work as it does now.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.