# vJine.Lua **Repository Path**: AgileMu2/vJine.Lua ## Basic Information - **Project Name**: vJine.Lua - **Description**: vJine.Lua 是基于原生Lua的C# Wrapper - **Primary Language**: Unknown - **License**: MPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 5 - **Created**: 2016-04-09 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #vJine.Lua *** >vJine.Lua是Lua语言的C#封装库,可实现通过C#直接运行Lua脚本并与Lua脚本交互的功能。 *** ##1. 授权: [MPL2.0](https://www.mozilla.org/MPL/2.0/ "") ##相关资源: nuget:(https://www.nuget.org/packages?q=vjine) API文档:(http://git.oschina.net/vjine/vJine.Lua/attach_files) Lua官网:(http://www.lua.org) Lua中国开发者:(http://www.luaer.cn) babelua\(基于Visual Studio扩展的Lua编辑器\):(https://babelua.codeplex.com/) QQ群:115051701 ##2. 说明: 1)vJine.Lua采用C++/CIL封装自Lua,当前Lua版本为(Lua 5.3.0) 2)暂不支持方法重载,注入时同名方法将被覆盖。 ##3. 功能简介: //引用命名空间 ```cs using vJine.Lua; ``` //获取Lua版本 ```cs string V = LuaContext.Version; ``` //实例化LuaContext ```cs LuaContext luaContext = new LuaContext(); ``` ```cs string vars_name = "vJine.Lua.Vars.bool"; ``` //设置与读取堆栈变量 ```cs bool v_bool = true; luaContext.set(true); luaContext.get(out v_bool); Debug.Assert(v_bool == true); luaContext.set(false); luaContext.get(out v_bool); Debug.Assert(v_bool == false); ``` //设置与读取全局变量 ```cs luaContext.set(vars_name, true); luaContext.get(vars_name, out v_bool); Debug.Assert(v_bool == true); luaContext.set(vars_name, false); luaContext.get(vars_name, out v_bool); Debug.Assert(v_bool == false); ``` //注册:匿名方法 ```cs luaContext.reg("vJine.Lua.funcs.anony", new Action((MyStatus E) => { string msg = string.Format("result[anonymous]:{0}", E); })); ``` //注册:静态方法 ```cs luaContext.reg("vJine.Lua.funcs.M", new Action(MyClass.M)); ``` //注册:实例方法 ```cs MyClass xq = new MyClass(); luaContext.reg("vJine.Lua.funcs.m", new Action(x1.m)); ``` //注册类:默认名称 ```cs luaContext.reg(); ``` //注册类:自定义名称 ```cs luaContext.reg("vJine.Lua.YourClass"); ``` //注入脚本: ```cs object[] R = luaContext.inject( "function callback(my_arg) return my_arg .. ' on_the_fly' end return true, 1.234, callback('vJine.Lua')"); ``` //调用脚本 ```cs object[] Obj = luaContext.exec("callback", "vJine.Lua"); ``` //加载脚本: ```cs R = luaContext.load("d:/vJine.Lua/start.lua"); ``` //打印堆栈变量: ```cs luaContext.print_vars(); ``` //打印全局变量: ```cs luaContext.print_var("vJine.Lua.UT.MyClass"); ``` //类定义: ```cs public class MyClass { public MyClass My { get; set; } public bool B { get; set; } public bool? b { get; set; } public byte[] B_ { get; set; } public double D { get; set; } public double d { get; set; } public Guid G { get; set; } public Guid? g { get; set; } public Guid[] G_ { get; set; } public string S { get; set; } public string s { get; set; } public string[] s_ { get; set; } public DateTime DT { get; set; } public DateTime? dt { get; set; } public DateTime[] DT_ { get; set; } public MyStatus E { get; set; } public MyStatus? e { get; set; } public MyStatus[] E_ { get; set; } public static void M(MyStatus E) { string msg = string.Format("result[anonymous]:{0}", E); } public void m(MyStatus E) { string msg = string.Format("result[anonymous]:{0}", E); } public static string SM(int a, string b) { return string.Format("SM:Result:a,{0};b,{1}", a, b); } public string IM(int a, string b) { return string.Format("IM:Result:a,{0};b,{1}", a, b); } public string show_properties() { return string.Format("Properties:b,{0};d,{1};s,{2}", this.B, this.D, this.s); } } ```