Пример #1
0
        public LuaRuntime(object mark)
        {
            _mark = mark;
            var that = this;

            Script    = string.Empty;
            _disposer = new RuntimeDisposer(() =>
            {
                Script = string.Empty;
                that._hookManager.RemoveHook();
                HookManagerPool.Remove(that.State);
                LuaCore.Close(that.State);
                LuaRuntimePool.Remove(that.State);
                ObjectMgr.Dispose();
                ClassMgr.Dispose();
            });
            _luaState      = LuaCore.Initialze();
            _funcMgr       = new FunctionManager(_luaState);
            _classMgr      = new ClassManager(_luaState);
            _objectManager = new ObjectManager();

            LuaCore.Atpanic(State, ShowError);
            LuaRuntimePool.Add(_luaState, this);

            _hookManager = new HookManager(that);
            _hookManager.SetHook(EventMasks.All, 0);

            HookManagerPool.SetGlobalHookCallback();
            HookManagerPool.Add(_luaState, _hookManager);
        }
Пример #2
0
        public IScriptFunction Register(string fullPath, Func <IList <object>, object> func)
        {
            var runtime = LuaRuntimePool.GetRuntime(_luaState);

            runtime[fullPath] = new ScriptFunctionHandler(new DelegateWrapper(func).Invoker);

            var luaFunc = runtime[fullPath] as ScriptFunctionHandler;

            return(new ScriptFunction(_luaState, luaFunc));
        }