Esempio n. 1
0
        public void Destroy()
        {
            try
            {
                _instance = null;
                if (_ctx != null)
                {
                    var ctx = _ctx.rawValue;
                    _ctx.Destroy();
                    _ctx            = null;
                    _lastContextPtr = IntPtr.Zero;
                    _lastContext    = null;
                    _contexts.Clear();
                    _objectCache.Clear();
                    DuktapeDLL.duk_unity_destroy_heap(ctx);
                    // Debug.LogWarning("duk_destroy_heap");
                }

                if (_updateTimer != 0)
                {
                    DuktapeRunner.Clear(_updateTimer);
                    _updateTimer = 0;
                }
            }
            finally
            {
                if (_memAllocPool != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(_memAllocPool);
                    _memAllocPool = IntPtr.Zero;
                }
            }
        }
Esempio n. 2
0
        private static IEnumerator DuktapeCoroutineRun(DuktapeObject val)
        {
            // scratch code

            val.PushProperty(val.ctx, "thread");
            var thread = DuktapeDLL.duk_get_context(val.ctx, -1);

            DuktapeDLL.duk_pop(val.ctx);
            if (thread == IntPtr.Zero || thread == val.ctx)
            {
                Debug.LogError("invalid thread ptr");
                yield break;
            }
            var  context = new DuktapeContext(val.context.vm, thread);
            bool returnValue;

            do
            {
                returnValue = val.InvokeMemberWithBooleanReturn("next");
                var value = val.GetProperty("value");
                yield return(value);
            } while (returnValue);
            context.Destroy();
        }