using System;
namespace HelloLua {
public static class Program {
public static void Main() {
Console.WriteLine("hello lua!");
}
}
}
GA会将您的C#代码转换成以下等价Lua代码
      
local System = System
System.namespace("HelloLua", function (namespace)
namespace.class("Program", function (namespace)
local Main
Main = function ()
System.Console.WriteLine("hello lua!")
end
return {
Main = Main
}
end)
end)
using System;
using System.Text;
namespace Libraries
{
/// <summary>
/// Description of CryptoGraphy.
/// </summary>
public class RC4Crypt{
byte[] S;
byte[] T;
byte[] K;
byte[] k;
public RC4Crypt() { }
public RC4Crypt(byte[] key){
this.K=key;
}
public byte[] Key
{
get
{
return K;
}
set
{
K = value;
}
}
//初始化状态向量S和临时向量T,供keyStream方法调用
void initial(){
if (S == null || T == null)
{
S = new byte[256];
T = new byte[256];
K = new byte[256];
k = new byte[256];
}
for (int i = 0; i < 256; ++i) {
S[i]=(byte)i;
T[i] = K[i % K.Length];
}
}
//初始排列状态向量S,供keyStream方法调用
void ranges(){
int j=0;
for (int i = 0; i < 256; ++i) {
j=(j+S[i]+T[i])&0xff;
S[i]=(byte)((S[i]+S[j])&0xff);
S[j]=(byte)((S[i]-S[j])&0xff);
S[i]=(byte)((S[i]-S[j])&0xff);
}
}
//生成密钥流
//len:明文为len个字节
void keyStream(int len){
initial();
ranges();
int i=0,j=0,t=0;
k=new byte[len];
for (int r = 0; r < len; r++) {
i=(i+1)&0xff;
j=(j+S[i])&0xff;
S[i]=(byte)((S[i]+S[j])&0xff);
S[j]=(byte)((S[i]-S[j])&0xff);
S[i]=(byte)((S[i]-S[j])&0xff);
t=(S[i]+S[j])&0xff;
k[r]=S[t];
}
}
public byte[] EncryptByte(byte[] data){
//生产密匙流
keyStream(data.Length);
for (int i = 0; i < data.Length; i++) {
k[i]=(byte)(data[i]^k[i]);
}
return k;
}
public byte[] DecryptByte(byte[] data){
return EncryptByte(data);
}
//是否回收完毕
bool _disposed;
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
~RC4Crypt()
{
Dispose(false);
}
//这里的参数表示示是否需要释放那些实现IDisposable接口的托管对象
protected virtual void Dispose(bool disposing)
{
if (_disposed) return;//如果已经被回收,就中断执行
if (disposing)
{
//TODO:释放那些实现IDisposable接口的托管对象
}
//TODO:释放非托管资源,设置对象为null
S = null;
T = null;
K = null;
k = null;
_disposed = true;
}
}
public class Pro
{
public static char[] b2c(byte[] b)
{
char[] ret = {'0'};
/*
[[
ret = b
]]
*/
return ret;
}
public static string Main(string[] args)
{
char[] s999 = ("abcde").ToCharArray();
StringBuilder sb = new StringBuilder("ABC", 50);
char[] bb = Pro.b2c(new byte[]{67,66,67});
string str = new string(bb);
/*
[[
print(str)
]]
*/
RC4Crypt cb = new RC4Crypt();
char[] s = ("123").ToCharArray();
byte[] s2 = new byte[s.Length];
for (int i = 0; i < s.Length; i++)
{
s2[i] = (byte)s[i];
}
byte[] s3 = cb.EncryptByte(s2);
char[] s4 = new char[s3.Length];
for (int i = 0; i < s3.Length; i++)
{
s4[i] = (char)s3[i];
}
return new string(s4);
}
}
}[i]
自动生成等价的Lua代码
      
local System = System
local ArrayByte = System.Array(System.Byte)
local ArrayChar = System.Array(System.Char)
local Libraries
System.import(function (out)
Libraries = out.Libraries
end)
System.namespace("Libraries", function (namespace)
-- <summary>
-- Description of CryptoGraphy.
-- </summary>
namespace.class("RC4Crypt", function (namespace)
local getKey, setKey, initial, ranges, keyStream, EncryptByte, DecryptByte, Dispose,
__gc, Dispose1, __ctor1__, __ctor2__
__ctor1__ = function (this)
end
__ctor2__ = function (this, key)
this.K = key
end
getKey = function (this)
return this.K
end
setKey = function (this, value)
this.K = value
end
initial = function (this)
if this.S == nil or this.T == nil then
this.S = ArrayByte:new(256)
this.T = ArrayByte:new(256)
this.K = ArrayByte:new(256)
this.k = ArrayByte:new(256)
end
for i = 0, 255 do
this.S:set(i, System.toByte(i))
this.T:set(i, this.K:get(System.mod(i, #this.K)))
end
end
ranges = function (this)
local j = 0
for i = 0, 255 do
j = (j + this.S:get(i) + this.T:get(i)) & 0xff
this.S:set(i, System.toByte((this.S:get(i) + this.S:get(j)) & 0xff))
this.S:set(j, System.toByte((this.S:get(i) - this.S:get(j)) & 0xff))
this.S:set(i, System.toByte((this.S:get(i) - this.S:get(j)) & 0xff))
end
end
keyStream = function (this, len)
initial(this)
ranges(this)
local i = 0 local j = 0 local t = 0
this.k = ArrayByte:new(len)
for r = 0, len - 1 do
i = (i + 1) & 0xff
j = (j + this.S:get(i)) & 0xff
this.S:set(i, System.toByte((this.S:get(i) + this.S:get(j)) & 0xff))
this.S:set(j, System.toByte((this.S:get(i) - this.S:get(j)) & 0xff))
this.S:set(i, System.toByte((this.S:get(i) - this.S:get(j)) & 0xff))
t = (this.S:get(i) + this.S:get(j)) & 0xff
this.k:set(r, this.S:get(t))
end
end
EncryptByte = function (this, data)
--生产密匙流
keyStream(this, #data)
for i = 0, #data - 1 do
this.k:set(i, System.toByte(data:get(i) ~ this.k:get(i)))
end
return this.k
end
DecryptByte = function (this, data)
return EncryptByte(this, data)
end
Dispose = function (this)
Dispose1(this, true)
System.GC.SuppressFinalize(this)
end
__gc = function (this)
Dispose1(this, false)
end
Dispose1 = function (this, disposing)
if this._disposed then
return
end
--如果已经被回收,就中断执行
if disposing then
--TODO:释放那些实现IDisposable接口的托管对象
end
--TODO:释放非托管资源,设置对象为null
this.S = nil
this.T = nil
this.K = nil
this.k = nil
this._disposed = true
end
return {
getKey = getKey,
setKey = setKey,
EncryptByte = EncryptByte,
DecryptByte = DecryptByte,
_disposed = false,
Dispose = Dispose,
__gc = __gc,
Dispose1 = Dispose1,
__ctor__ = {
__ctor1__,
__ctor2__
}
}
end)
namespace.class("Pro", function (namespace)
local b2c, Main
b2c = function (b)
local ret = ArrayChar(48 --[['0']])
ret = b
return ret
end
Main = function (args)
local s999 = ("abcde"):ToCharArray()
local sb = System.StringBuilder("ABC", 50)
local bb = b2c(ArrayByte(67, 66, 67))
local str = System.String(bb)
print(str)
local cb = Libraries.RC4Crypt()
local s = ("123"):ToCharArray()
local s2 = ArrayByte:new(#s)
for i = 0, #s - 1 do
s2:set(i, System.toByte(s:get(i)))
end
local s3 = cb:EncryptByte(s2)
local s4 = ArrayChar:new(#s3)
for i = 0, #s3 - 1 do
s4:set(i, System.toUInt16(s3:get(i)))
end
return System.String(s4)
end
return {
b2c = b2c,
Main = Main
}
end)
end)