CCSharp allows you to write ComputerCraft programs in C# by transpiling them into Lua.
[LuaProgram]
public static class LogKeyEvents
{
[LuaMain]
public static void Start()
{
while (true)
{
KeyEvent keyEvent = OS.PullEvent<KeyEvent>();
Console.WriteLine(Keys.GetName(keyEvent.Key) + " held=" + keyEvent.Held);
}
}
}function Start()
while true do
local keyEvent = {os.pullEvent("key")};
print((tostring(keys.getName(keyEvent[2])).." held=")..tostring(keyEvent[3]))
end
end
Start()- Update to newer version of ICSharpCode.Decompiler
- Fix string concatenation (this will happen with the ICSharpCode.Decompiler update)
- Compile get and set accessors for non auto implemented properties (need to decide if I want to use __index and __newindex to mimic how it works in C# or just generate regular get_* and set_* methods)
- A compile flag on [LuaProgram] to have all dependent [LuaClass] be compiled as modules
- try catch support via xpcall
- Support for all Linq functions
- Improve documentation
- Support for [LuaClass] on structs by generating a copy method that gets called automatically when passing by value
- An option to preserve local variable names by providing pdb to ICSharpCode.Decompiler
- Support multiple operator overloads with varying types (ex: a vector that can be multiplied by both another vector or a scalar value)
- Add proper unit tests to CCSharp.Tests that get run in CraftOS-PC
- Create adapter classes for the full computercraft api
- Create adapter classes for various peripheral mod apis (if you PR these separate each mod intos its own namespace)
- ToArray
- ToList
- GroupBy
- OrderBy
- OrderByDescending
- Where
- Select
- Distinct
- Take
- First
- FirstOrDefault
- Count
- LongCount
- Any
- Sum
- out parameters
- async
- Reflection
CCSharp.Demo contains a few demo programs to test various functionality.
CCSharp.Tests contains a few test programs, eventually this will run proper unit tests.
CCSharp uses ICSharpCode.Decompiler to decompile C# programs into a C# syntax tree.
RedIL is an intermediate language that is created from decompiled C# syntax tree, and later compiled to Lua. It's name comes from the original library this was forked from, RediSharp
Lua is written by traversing the RedIL using an IRedILVisitor.
See the Lua folder.
All of the classes that actually adapt the ComputerCraft api can be found in the ComputerCraft namespace
- ICSharpCode.Decompiler which is the decompiler engine built for ILSpy
- RediSharp Project is based on and uses it's RedIL but further expanded to handle full programs, classes, and better adapt exising lua apis.
