private static int _GetTimerFunction(IntPtr ctx, out DuktapeFunction fn) { if (!DuktapeDLL.duk_is_function(ctx, 0)) { fn = null; return(0); } if (!DuktapeDLL.duk_is_number(ctx, 1)) { fn = null; return(1); } var top_index = DuktapeDLL.duk_get_top_index(ctx); // Debug.Log($"_GetTimerFunction {top} ?? {DuktapeDLL.duk_get_top(ctx)}"); DuktapeValue[] argv = null; if (top_index > 1) { argv = new DuktapeValue[top_index - 1]; for (var i = 2; i <= top_index; i++) { DuktapeDLL.duk_dup(ctx, i); var argPtr = DuktapeDLL.duk_get_heapptr(ctx, -1); argv[i - 2] = new DuktapeValue(ctx, DuktapeDLL.duk_unity_ref(ctx), argPtr); } } DuktapeDLL.duk_dup(ctx, 0); var fnPtr = DuktapeDLL.duk_get_heapptr(ctx, -1); fn = new DuktapeFunction(ctx, DuktapeDLL.duk_unity_ref(ctx), fnPtr, argv); return(-1); }
private static bool Equals(DuktapeValue x, DuktapeValue y) { var ctx = x._context.rawValue; x.Push(ctx); y.Push(ctx); var eq = DuktapeDLL.duk_equals(ctx, -1, -2); DuktapeDLL.duk_pop_2(ctx); return(eq); }
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); }