示例#1
0
    static void ShowWindow()
    {
        luaModulePath = GameSetting.LuaDir + "modules/";

        myWindow = EditorWindow.CreateInstance <LuaModule>();
        myWindow.Show();
    }
示例#2
0
        public void LoadModuleInfo(LuaModule module, int index)
        {
            Index = index;
            _module = module;

            scriptNameEntry.Text = _module.ScriptName;
            scriptURL.Text = _module.LuaURL;
            resourceURL.Text = _module.ResURL;
            screenshotURL.Text = _module.ScreenshotURL;
            usageExample.Buffer.Text = _module.UsageExample;
        }
示例#3
0
        public LuaModuleBrowser(LuaModule module)
        {
            Module = module;

            InitializeComponent();

            tree.Nodes.Add("Endianness: " + module.Endianness);
            tree.Nodes.Add("Version: " + module.VersionString);

            TreeNode root = FunctionToTree(module.Main);

            root.Expand();
            tree.Nodes.Add(root);
        }
示例#4
0
    void LoadScript(string path)
    {
        string ext = Path.GetExtension(path);

        if (ext.ToLower().Equals(".lua"))
        {
            m_Module = LuaModule.CreateModule(path);
            m_Module.Load(path);
        }
        else
        {
            Debug.LogWarning("expect a lua file" + path);
        }
    }
示例#5
0
    public static LuaModule CreateModule(string path)
    {
        LuaModule ret;

        if (m_LuaModuleList.TryGetValue(path, out ret))
        {
            Debug.LogWarning("script always exists: " + path);
            return(ret);
        }

        ret = new LuaModule();
        m_LuaModuleList.Add(path, ret);
        return(ret);
    }
示例#6
0
 static int GetLuaModule(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         GameManager obj = (GameManager)ToLua.CheckObject(L, 1, typeof(GameManager));
         LuaModule   o   = obj.GetLuaModule();
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
示例#7
0
    public static LuaModule GetLuaModule()
    {
        if (_testLuaModule != null)
        {
            return(_testLuaModule);
        }

        var luaModule = LuaModule.Instance;
        var em        = luaModule.Init();

        while (em.MoveNext())
        {
        }
        _testLuaModule = luaModule;
        return(luaModule);
    }
示例#8
0
    static int get_recvCount(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            LuaModule obj = (LuaModule)o;
            int       ret = obj.recvCount;
            LuaDLL.lua_pushinteger(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index recvCount on a nil value" : e.Message));
        }
    }
示例#9
0
 static int RunLuaRequest(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 4);
         LuaModule  obj  = (LuaModule)ToLua.CheckObject(L, 1, typeof(LuaModule));
         uint       arg0 = (uint)LuaDLL.luaL_checknumber(L, 2);
         byte[]     arg1 = ToLua.CheckByteBuffer(L, 3);
         Connection arg2 = (Connection)ToLua.CheckObject(L, 4, typeof(Connection));
         obj.RunLuaRequest(arg0, arg1, arg2);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
示例#10
0
        private static string _checkObjectSubclass(int contextId, string className)
        {
            LuaContext context = LuaContext.getContext(contextId);

            if (context != null)
            {
                if (_exportsClasses.ContainsKey(contextId) && _exportsClasses [contextId] != null && _exportsClasses [contextId].ContainsKey(className))
                {
                    Type t = _exportsClasses [contextId] [className];
                    if (t.IsSubclassOf(typeof(LuaObjectClass)))
                    {
                        LuaModule.register(context, t);
                        return(LuaModule.moduleName(t));
                    }
                }
            }
            return(null);
        }
示例#11
0
    static int _CreateLuaModule(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 0)
            {
                LuaModule obj = new LuaModule();
                ToLua.PushObject(L, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: LuaModule.New"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
示例#12
0
        /// <summary>
        /// 注册模块
        /// </summary>
        /// <param name="context">Lua上下文对象.</param>
        /// <param name="moduleName">模块名称.</param>
        /// <param name="t">类型.</param>
        protected static new void _register(LuaContext context, string moduleName, Type t)
        {
            Type baseType = t.BaseType;

            string superClassName = null;

            if (baseType != typeof(LuaModule))
            {
                superClassName = LuaModule.moduleName(baseType);
                if (!context.isModuleRegisted(superClassName))
                {
                    //尚未注册父类,进行父类注册
                    LuaModule.register(context, baseType);
                }
            }

            //获取导出的类/实例方法
            Dictionary <string, MethodInfo> exportClassMethods = new Dictionary <string, MethodInfo> ();
            List <string> exportClassMethodNames = new List <string> ();

            Dictionary <string, MethodInfo> exportInstanceMethods = new Dictionary <string, MethodInfo> ();
            List <string> exportInstanceMethodNames = new List <string> ();

            MethodInfo[] methods = t.GetMethods();
            foreach (MethodInfo m in methods)
            {
                if (m.IsStatic && m.IsPublic)
                {
                    //静态和公开的方法会导出到Lua
                    exportClassMethodNames.Add(m.Name);
                    exportClassMethods.Add(m.Name, m);
                }
                else if (m.IsPublic)
                {
                    //实例方法
                    exportInstanceMethodNames.Add(m.Name);
                    exportInstanceMethods.Add(m.Name, m);
                }
            }

            //获取导出的字段
            Dictionary <string, PropertyInfo> exportFields = new Dictionary <string, PropertyInfo> ();
            List <string> exportSetterNames = new List <string> ();
            List <string> exportGetterNames = new List <string> ();

            PropertyInfo[] propertys = t.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            foreach (PropertyInfo p in propertys)
            {
                if (p.CanRead)
                {
                    exportGetterNames.Add(p.Name);
                }
                if (p.CanWrite)
                {
                    exportSetterNames.Add(p.Name);
                }
                exportFields.Add(p.Name, p);
            }

            //创建导出的字段数据
            IntPtr exportSetterNamesPtr = IntPtr.Zero;

            if (exportSetterNames.Count > 0)
            {
                LuaObjectEncoder fieldEncoder = new LuaObjectEncoder();
                fieldEncoder.writeInt32(exportSetterNames.Count);
                foreach (string name in exportSetterNames)
                {
                    fieldEncoder.writeString(name);
                }

                byte[] fieldNameBytes = fieldEncoder.bytes;
                exportSetterNamesPtr = Marshal.AllocHGlobal(fieldNameBytes.Length);
                Marshal.Copy(fieldNameBytes, 0, exportSetterNamesPtr, fieldNameBytes.Length);
            }

            IntPtr exportGetterNamesPtr = IntPtr.Zero;

            if (exportGetterNames.Count > 0)
            {
                LuaObjectEncoder fieldEncoder = new LuaObjectEncoder();
                fieldEncoder.writeInt32(exportGetterNames.Count);
                foreach (string name in exportGetterNames)
                {
                    fieldEncoder.writeString(name);
                }

                byte[] fieldNameBytes = fieldEncoder.bytes;
                exportGetterNamesPtr = Marshal.AllocHGlobal(fieldNameBytes.Length);
                Marshal.Copy(fieldNameBytes, 0, exportGetterNamesPtr, fieldNameBytes.Length);
            }


            //创建导出的实例方法数据
            IntPtr exportInstanceMethodNamesPtr = IntPtr.Zero;

            if (exportInstanceMethodNames.Count > 0)
            {
                LuaObjectEncoder instanceMethodEncoder = new LuaObjectEncoder();
                instanceMethodEncoder.writeInt32(exportInstanceMethodNames.Count);
                foreach (string name in exportInstanceMethodNames)
                {
                    instanceMethodEncoder.writeString(name);
                }

                byte[] instMethodNameBytes = instanceMethodEncoder.bytes;
                exportInstanceMethodNamesPtr = Marshal.AllocHGlobal(instMethodNameBytes.Length);
                Marshal.Copy(instMethodNameBytes, 0, exportInstanceMethodNamesPtr, instMethodNameBytes.Length);
            }


            //创建导出类方法数据
            IntPtr exportClassMethodNamesPtr = IntPtr.Zero;

            if (exportClassMethodNames.Count > 0)
            {
                LuaObjectEncoder classMethodEncoder = new LuaObjectEncoder();
                classMethodEncoder.writeInt32(exportClassMethodNames.Count);
                foreach (string name in exportClassMethodNames)
                {
                    classMethodEncoder.writeString(name);
                }

                byte[] classMethodNameBytes = classMethodEncoder.bytes;
                exportClassMethodNamesPtr = Marshal.AllocHGlobal(classMethodNameBytes.Length);
                Marshal.Copy(classMethodNameBytes, 0, exportClassMethodNamesPtr, classMethodNameBytes.Length);
            }

            //创建实例方法
            if (_createInstanceDelegate == null)
            {
                _createInstanceDelegate = new LuaInstanceCreateHandleDelegate(_createInstance);
            }

            //销毁实例方法
            if (_destroyInstanceDelegate == null)
            {
                _destroyInstanceDelegate = new LuaInstanceDestroyHandleDelegate(_destroyInstance);
            }

            //类描述
            if (_instanceDescriptionDelegate == null)
            {
                _instanceDescriptionDelegate = new LuaInstanceDescriptionHandleDelegate(_instanceDescription);
            }

            //字段获取器
            if (_fieldGetterDelegate == null)
            {
                _fieldGetterDelegate = new LuaInstanceFieldGetterHandleDelegate(_fieldGetter);
            }

            //字段设置器
            if (_fieldSetterDelegate == null)
            {
                _fieldSetterDelegate = new LuaInstanceFieldSetterHandleDelegate(_fieldSetter);
            }

            //实例方法处理器
            if (_instanceMethodHandlerDelegate == null)
            {
                _instanceMethodHandlerDelegate = new LuaInstanceMethodHandleDelegate(_instanceMethodHandler);
            }

            //类方法处理器
            if (_classMethodHandleDelegate == null)
            {
                _classMethodHandleDelegate = new LuaModuleMethodHandleDelegate(_classMethodHandler);
            }

            int nativeId = NativeUtils.registerClass(
                context.objectId,
                moduleName,
                superClassName,
                exportSetterNamesPtr,
                exportGetterNamesPtr,
                exportInstanceMethodNamesPtr,
                exportClassMethodNamesPtr,
                Marshal.GetFunctionPointerForDelegate(_createInstanceDelegate),
                Marshal.GetFunctionPointerForDelegate(_destroyInstanceDelegate),
                Marshal.GetFunctionPointerForDelegate(_instanceDescriptionDelegate),
                Marshal.GetFunctionPointerForDelegate(_fieldGetterDelegate),
                Marshal.GetFunctionPointerForDelegate(_fieldSetterDelegate),
                Marshal.GetFunctionPointerForDelegate(_instanceMethodHandlerDelegate),
                Marshal.GetFunctionPointerForDelegate(_classMethodHandleDelegate));

            //关联注册模块的注册方法
            _exportsClass[nativeId]           = t;
            _exportsClassMethods[nativeId]    = exportClassMethods;
            _exportsInstanceMethods[nativeId] = exportInstanceMethods;
            _exportsFields[nativeId]          = exportFields;

            if (exportSetterNamesPtr != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(exportSetterNamesPtr);
            }
            if (exportGetterNamesPtr != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(exportGetterNamesPtr);
            }
            if (exportInstanceMethodNamesPtr != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(exportInstanceMethodNamesPtr);
            }
            if (exportClassMethodNamesPtr != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(exportClassMethodNamesPtr);
            }
        }
示例#13
0
        /// <summary>
        /// 注册模块
        /// </summary>
        /// <param name="context">Lua上下文对象.</param>
        /// <param name="moduleName">模块名称.</param>
        /// <param name="t">类型.</param>
        protected static new void _register(LuaContext context, string moduleName, Type t)
        {
            if (_checkObjectSubclassDelegate == null)
            {
                _checkObjectSubclassDelegate = new LuaCheckObjectSubclassDelegate(_checkObjectSubclass);
            }

            if (_allowExportClassDelegate == null)
            {
                _allowExportClassDelegate = new LuaAllowExportClassDelegate(_allowExportsClass);
            }

            if (_allExportClassMethodsDelegate == null)
            {
                _allExportClassMethodsDelegate = new LuaAllExportClassMethodsDelegte(_allExportClassMethods);
            }

            if (_allExportInstanceMethodsDelegate == null)
            {
                _allExportInstanceMethodsDelegate = new LuaAllExportInstanceMethodsDelegte(_allExportInstanceMethods);
            }

            if (_allExportInstanceFieldGettersDelegate == null)
            {
                _allExportInstanceFieldGettersDelegate = new LuaAllExportInstanceFieldGettersDelegate(_allExportInstanceFieldGetters);
            }

            if (_allExportInstanceFieldSettersDelegate == null)
            {
                _allExportInstanceFieldSettersDelegate = new LuaAllExportInstanceFieldSettersDelegate(_allExportInstanceFieldSetters);
            }

            if (_createNativeObjectDelegate == null)
            {
                _createNativeObjectDelegate = new LuaCreateNativeObjectDelegate(_createInstance);
            }

            if (_classMethodInvokeDelegate == null)
            {
                _classMethodInvokeDelegate = new LuaNativeClassMethodHandleDelegate(_classMethodInvoke);
            }

            if (_instanceMethodInvokeDelegate == null)
            {
                _instanceMethodInvokeDelegate = new LuaNativeInstanceMethodHandleDelegate(_instanceMethodInvoke);
            }

            if (_fieldGetterInvokeDelegate == null)
            {
                _fieldGetterInvokeDelegate = new LuaNativeInstanceFieldGetterHandleDelegate(_filedGetterInvoke);
            }

            if (_fieldSetterInvokeDelegate == null)
            {
                _fieldSetterInvokeDelegate = new LuaNativeInstanceFieldSetterHandleDelegate(_fieldSetterInvoke);
            }

            NativeUtils.registerClassImport(
                context.objectId,
                LuaModule.moduleName(t),
                Marshal.GetFunctionPointerForDelegate(_checkObjectSubclassDelegate),
                Marshal.GetFunctionPointerForDelegate(_allowExportClassDelegate),
                Marshal.GetFunctionPointerForDelegate(_allExportClassMethodsDelegate),
                Marshal.GetFunctionPointerForDelegate(_allExportInstanceMethodsDelegate),
                Marshal.GetFunctionPointerForDelegate(_allExportInstanceFieldGettersDelegate),
                Marshal.GetFunctionPointerForDelegate(_allExportInstanceFieldSettersDelegate),
                Marshal.GetFunctionPointerForDelegate(_createNativeObjectDelegate),
                Marshal.GetFunctionPointerForDelegate(_classMethodInvokeDelegate),
                Marshal.GetFunctionPointerForDelegate(_instanceMethodInvokeDelegate),
                Marshal.GetFunctionPointerForDelegate(_fieldGetterInvokeDelegate),
                Marshal.GetFunctionPointerForDelegate(_fieldSetterInvokeDelegate));
        }
示例#14
0
 public AD7Module(LuaModule debuggedModule)
 {
     this.DebuggedModule = debuggedModule;
 }