随风逐叶 随风逐叶
首页
  • Quick Reference (opens new window)
  • EgretEngine开发者文档 (opens new window)
  • TinaX框架
  • SSH教程
  • VSCode插件开发
关于
  • 分类
  • 标签
  • 归档

rontian

从事游戏开发10多年的老菜鸟一枚!
首页
  • Quick Reference (opens new window)
  • EgretEngine开发者文档 (opens new window)
  • TinaX框架
  • SSH教程
  • VSCode插件开发
关于
  • 分类
  • 标签
  • 归档
  • 框架简介
  • TinaX.Core
  • 基于TinaX创建一个扩展库
  • TinaX.VFS
  • TinaX.UIKit
  • TinaX.I18N
  • TinaX.Lua
    • XLua

    • Google.Protobuf
    • Lua-Protobuf
    • 一些优秀的第三方库

    目录

    TinaX.Lua

    # TinaX.Lua

    # 简介

    基于xLua的Lua运行环境.做了一些基础的封装和扩展

    由于所使用的第三方库Tencent/xLua的限制,TinaX.Lua只能放在Assembly-CSharp中(即直接放在项目Assets目录下的某个地方)。

    # 集成第三方库json,protobuf等

    namespace XLua.LuaDLL
    {
        using System.Runtime.InteropServices;
    
        public partial class Lua
        {
            [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
            public static extern int luaopen_rapidjson(System.IntPtr L);
    
            [MonoPInvokeCallback(typeof(LuaDLL.lua_CSFunction))]
            public static int LoadRapidJson(System.IntPtr L)
            {
                return luaopen_rapidjson(L);
            }
    
            [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
            public static extern int luaopen_lpeg(System.IntPtr L);
    
            [MonoPInvokeCallback(typeof(LuaDLL.lua_CSFunction))]
            public static int LoadLpeg(System.IntPtr L)
            {
                return luaopen_lpeg(L);
            }
    
            [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
            public static extern int luaopen_pb(System.IntPtr L);
    
            [MonoPInvokeCallback(typeof(LuaDLL.lua_CSFunction))]
            public static int LoadLuaProfobuf(System.IntPtr L)
            {
                return luaopen_pb(L);
            }
    
            [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
            public static extern int luaopen_protobuf_c(System.IntPtr L);
    
            [MonoPInvokeCallback(typeof(LuaDLL.lua_CSFunction))]
            public static int LoadProtobufC(System.IntPtr L)
            {
                return luaopen_protobuf_c(L);
            }
    
            [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
            public static extern int luaopen_ffi(System.IntPtr L);
    
            [MonoPInvokeCallback(typeof(LuaDLL.lua_CSFunction))]
            public static int LoadFFI(System.IntPtr L)
            {
                return luaopen_ffi(L);
            }
        }
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52

    加载库到Lua虚拟机

    var service = core.Services.Get<ILua>();
    service.LuaVM.AddBuildin("rapidjson", XLua.LuaDLL.Lua.LoadRapidJson);
    service.LuaVM.AddBuildin("pb", XLua.LuaDLL.Lua.LoadLuaProfobuf);
    
    1
    2
    3

    # 设置Wrap导出规则

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Reflection;
    using UnityEngine;
    using XLua;
    
    namespace TinaXEditor.Lua.Internal
    {
        public static class LuaTypesConfig
        {
            [LuaCallCSharp]
            //[ReflectionUse]
            public static List<Type> LuaCallCSharpNestedTypes
            {
                get
                {
                    var types = new List<Type>();
                    foreach (var type in LuaCallCSharpList)
                    {
                        foreach (var nested_type in type.GetNestedTypes(BindingFlags.Public))
                        {
                            if ((!nested_type.IsAbstract && typeof(Delegate).IsAssignableFrom(nested_type))
                                || nested_type.IsGenericTypeDefinition)
                            {
                                continue;
                            }
                            types.Add(nested_type);
                        }
                    }
                    return types;
                }
            }
    
            [LuaCallCSharp]
            //[ReflectionUse]
            public static List<Type> LuaCallCSharpList = new List<Type>() {
    
                #region Unity
                //Unity
                typeof(UnityEngine.Application),
                typeof(GameObject),
                typeof(MonoBehaviour),
                typeof(Behaviour),
                typeof(Component),
                typeof(RectTransform),
                typeof(Transform),
                typeof(UnityEngine.UI.Text),
                typeof(UnityEngine.UI.Button),
                typeof(UnityEngine.UI.Image),
                typeof(UnityEngine.Events.UnityEvent),
                typeof(UnityEngine.Events.UnityEventBase),
                typeof(AudioClip),
                typeof(UnityEngine.Object),
                typeof(Application),
                typeof(Vector2),
                typeof(Vector3),
                #endregion
    
                #region TinaX
                typeof(TinaX.IXCore),
                typeof(TinaX.TimeMachine),
                typeof(TinaX.Systems.ITimeTicket),
                typeof(TinaX.XEvent),
                typeof(TinaX.Systems.IEventTicket),
    
                typeof(TinaX.GameObjectExtends),
                typeof(TinaX.StringExtend),
                typeof(TinaX.UObjectExtend),
                #endregion
    
    
                typeof(System.Object),
                typeof(List<int>),
                typeof(Action<string>),
                typeof(Action<int>),
    
    
                
            };
    
            [CSharpCallLua]
            public static List<Type> CSharpCallLuaList = new List<Type>()
            {
                typeof(Action),
                typeof(Action<int>),
                typeof(Action<string>),
                typeof(Action<string, string>),
                typeof(Action<string, int>),
                typeof(Action<double>),
                typeof(Action<bool>),
                typeof(Action<Collider>),
                typeof(Action<Collision>),
                typeof(Action<UnityEngine.Object>),
                typeof(Action<UnityEngine.Object,TinaX.XException>),
                typeof(Action<LuaFunction, Exception>),
                typeof(Action<object>),
            };
    
            [BlackList]
            public static Func<MemberInfo, bool> MethodFilter = (memberInfo) =>
            {
                if (memberInfo.DeclaringType.IsGenericType && memberInfo.DeclaringType.GetGenericTypeDefinition() == typeof(Dictionary<,>))
                {
                    if (memberInfo.MemberType == MemberTypes.Constructor)
                    {
                        ConstructorInfo constructorInfo = memberInfo as ConstructorInfo;
                        var parameterInfos = constructorInfo.GetParameters();
                        if (parameterInfos.Length > 0)
                        {
                            if (typeof(System.Collections.IEnumerable).IsAssignableFrom(parameterInfos[0].ParameterType))
                            {
                                return true;
                            }
                        }
                    }
                    else if (memberInfo.MemberType == MemberTypes.Method)
                    {
                        var methodInfo = memberInfo as MethodInfo;
                        if (methodInfo.Name == "TryAdd" || methodInfo.Name == "Remove" && methodInfo.GetParameters().Length == 2)
                        {
                            return true;
                        }
                    }
                }
                return false;
            };
    
            [BlackList]
            public static List<List<string>> BlackList = new List<List<string>>()  {
                //Unity--------------------------------------------
                new List<string>(){ "UnityEngine.UI.Text", "OnRebuildRequested"},
                new List<string>(){ "UnityEngine.MonoBehaviour", "runInEditMode"},
    
            };
    
        }
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138

    # 生成Wrap文件

    上次更新: 2023/10/17, 14:09:52 访问次数: 0
    TinaX.I18N
    简介

    ← TinaX.I18N 简介→

    最近更新
    01
    一些Shell常用的功能写法整理
    10-20
    02
    删除git仓库submodule的步骤
    10-20
    03
    django基本命令
    10-16
    更多文章>
    Copyright © 2017-2025 随风逐叶
    沪ICP备18008791号-1 | 沪公网安备31011502401077号

    网站访问总次数: 0次
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式