在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):frabert/NetLua开源软件地址(OpenSource Url):https://github.com/frabert/NetLua开源编程语言(OpenSource Language):C# 100.0%开源软件介绍(OpenSource Introduction):NetLuaProject descriptionNetLua is a completely managed interpreter for the Lua dynamic language. It was inspired by (and the LuaObject class is loosely based on) AluminumLua by Alexander Corrado. Check his project out at http://github.com/chkn/AluminumLua Why?I started this project because I needed a managed Lua interpreter and AluminumLua had a few bugs and caveats that were difficult to solve because of its structure. I so decided to do my own attempt at it. Source code parsingAs of now, the parsing is made using Irony, but any LALR parser can be used to build the internal AST interpreted by NetLua. Irony looks a bit slow, but it is the easiest solution for a neat C# LALR Parser. ExamplesUsing Lua from C#Lua lua = new Lua();
lua.DoString("a={4, b=6, [7]=10}"); // Interpreting Lua
var a = lua.Context.Get("a"); // Accessing Lua from C#
var a_b = a["b"].AsNumber();
double number = a[7]; // Automatic type coercion Registering C# methodsstatic LuaArguments print(LuaArguments args)
{
string[] strings = Array.ConvertAll<LuaObject, string>(args, x => x.ToString()); // LuaArguments can be used as a LuaObject array
Console.WriteLine(String.Join("\t", strings));
return Lua.Return(); // You can use the Lua.Return helper function to return values
}
Lua lua = new Lua();
lua.Context.SetGlobal("print", (LuaFunction)print); Using .NET 4.0 dynamic featuresdynamic lua = new Lua();
dynamic luaVariable = lua.var; // Lua.DynamicContext provides a dynamic version of Lua.Context
double a = luaVariable.numberValue; // Automatic type casting
double d = luaVariable.someFunc(a); // Automatic function arguments and result boxing / unboxing
lua.x = 5; |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论