Example #1
0
        public DuktapeThread(DuktapeFunction fn)
        {
            var ctx = fn.ctx;
            var vm  = DuktapeVM.GetContext(ctx).vm;
            var idx = DuktapeDLL.duk_push_thread(ctx);

            DuktapeDLL.duk_dup(ctx, -1);
            var ptr = DuktapeDLL.duk_get_heapptr(ctx, -1);

            _thread        = new DuktapeValue(ctx, DuktapeDLL.duk_unity_ref(ctx), ptr);
            _threadContext = new DuktapeContext(vm, DuktapeDLL.duk_get_context(ctx, idx));
            if (fn.Push(_threadContext.rawValue))
            {
            }

            DuktapeDLL.duk_pop(ctx);
        }
Example #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();
        }