• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

frabert/NetLua: Completely managed .NET Lua

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

frabert/NetLua

开源软件地址(OpenSource Url):

https://github.com/frabert/NetLua

开源编程语言(OpenSource Language):

C# 100.0%

开源软件介绍(OpenSource Introduction):

NetLua

Project description

NetLua 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 parsing

As 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.

Examples

Using 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# methods

static 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 features

dynamic 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;

Bitdeli Badge Build status




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
jonstoler/class.lua: object-oriented library for lua发布时间:2022-08-16
下一篇:
DelusionalLogic/pngLua: A pure lua implementation of a PNG decoder发布时间:2022-08-16
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap