public static bool duk_get_var(IntPtr ctx, int idx, out object o) { var jstype = DuktapeDLL.duk_get_type(ctx, idx); switch (jstype) { case duk_type_t.DUK_TYPE_BOOLEAN: /* ECMAScript boolean: 0 or 1 */ { o = DuktapeDLL.duk_get_boolean(ctx, idx); return(true); } case duk_type_t.DUK_TYPE_NUMBER: /* ECMAScript number: double */ { o = DuktapeDLL.duk_get_number(ctx, idx); return(true); } case duk_type_t.DUK_TYPE_STRING: /* ECMAScript string: CESU-8 / extended UTF-8 encoded */ { o = DuktapeDLL.duk_get_string(ctx, idx); return(true); } case duk_type_t.DUK_TYPE_OBJECT: /* ECMAScript object: includes objects, arrays, functions, threads */ { return(duk_get_cached_object(ctx, idx, out o)); } case duk_type_t.DUK_TYPE_BUFFER: /* fixed or dynamic, garbage collected byte buffer */ { uint length; var pointer = DuktapeDLL.duk_unity_get_buffer_data(ctx, idx, out length); var buffer = new byte[length]; o = buffer; Marshal.Copy(pointer, buffer, 0, (int)length); return(true); } case duk_type_t.DUK_TYPE_POINTER: /* raw void pointer */ case duk_type_t.DUK_TYPE_LIGHTFUNC: /* lightweight function pointer */ throw new NotImplementedException(); case duk_type_t.DUK_TYPE_NONE: /* no value, e.g. invalid index */ o = null; return(false); case duk_type_t.DUK_TYPE_UNDEFINED: /* ECMAScript undefined */ case duk_type_t.DUK_TYPE_NULL: /* ECMAScript null */ o = null; return(true); } o = null; return(false); }
public static int duk_assert(IntPtr ctx) { if (!DuktapeDLL.duk_get_boolean(ctx, 0)) { var msg = string.Empty; if (DuktapeDLL.duk_get_top(ctx) > 1) { msg = duk_print_string(ctx, 1, false); } return(DuktapeDLL.duk_generic_error(ctx, "assertion failed: " + msg)); } return(0); }
public static bool duk_get_primitive_array(IntPtr ctx, int idx, out bool[] o) { if (DuktapeDLL.duk_is_array(ctx, idx)) { var length = DuktapeDLL.duk_unity_get_length(ctx, idx); var nidx = DuktapeDLL.duk_normalize_index(ctx, idx); o = new bool[length]; for (var i = 0U; i < length; i++) { DuktapeDLL.duk_get_prop_index(ctx, idx, i); bool e; e = DuktapeDLL.duk_get_boolean(ctx, -1); //duk_get_primitive(ctx, -1, out e); o[i] = e; DuktapeDLL.duk_pop(ctx); } return(true); } duk_get_classvalue <bool[]>(ctx, idx, out o); return(true); }
public static bool duk_get_primitive(IntPtr ctx, int idx, out bool o) { o = DuktapeDLL.duk_get_boolean(ctx, idx); // no check return(true); }