public static bool duk_get_primitive_array(IntPtr ctx, int idx, out byte[] 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 byte[length]; for (var i = 0U; i < length; i++) { DuktapeDLL.duk_get_prop_index(ctx, idx, i); byte e; e = (byte)DuktapeDLL.duk_get_int(ctx, -1); // duk_get_primitive(ctx, -1, out e); o[i] = e; DuktapeDLL.duk_pop(ctx); } return(true); } if (DuktapeDLL.duk_is_buffer_data(ctx, idx)) { uint length; var pointer = DuktapeDLL.duk_unity_get_buffer_data(ctx, idx, out length); o = new byte[length]; Marshal.Copy(pointer, o, 0, (int)length); return(true); } duk_get_classvalue <byte[]>(ctx, idx, out o); return(true); }
public double GetDoubleValue(int index) { var ctx = _context.rawValue; this.Push(ctx); DuktapeDLL.duk_get_prop_index(ctx, -1, (uint)index); var res = 0.0; if (DuktapeDLL.duk_is_number(ctx, -1)) { res = DuktapeDLL.duk_get_number(ctx, -1); } DuktapeDLL.duk_pop_2(ctx); return(res); }
public float GetFloatValue(int index) { var ctx = _context.rawValue; this.Push(ctx); DuktapeDLL.duk_get_prop_index(ctx, -1, (uint)index); var res = 0f; if (DuktapeDLL.duk_is_number(ctx, -1)) { res = (float)DuktapeDLL.duk_get_number(ctx, -1); } DuktapeDLL.duk_pop_2(ctx); return(res); }
public string GetStringValue(int index) { var ctx = _context.rawValue; this.Push(ctx); DuktapeDLL.duk_get_prop_index(ctx, -1, (uint)index); string res = null; if (DuktapeDLL.duk_is_string(ctx, -1)) { res = DuktapeDLL.duk_get_string(ctx, -1); } DuktapeDLL.duk_pop_2(ctx); return(res); }
public static bool duk_get_type_array(IntPtr ctx, int idx, out Type[] 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 Type[length]; for (var i = 0U; i < length; i++) { DuktapeDLL.duk_get_prop_index(ctx, idx, i); Type e; duk_get_type(ctx, -1, out e); o[i] = e; DuktapeDLL.duk_pop(ctx); } return(true); } duk_get_classvalue <Type[]>(ctx, idx, out o); return(true); }
public static bool duk_get_primitive_array(IntPtr ctx, int idx, out sbyte[] 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 sbyte[length]; for (var i = 0U; i < length; i++) { DuktapeDLL.duk_get_prop_index(ctx, idx, i); sbyte e; e = (sbyte)DuktapeDLL.duk_get_int(ctx, -1); // duk_get_primitive(ctx, -1, out e); o[i] = e; DuktapeDLL.duk_pop(ctx); } return(true); } duk_get_classvalue <sbyte[]>(ctx, idx, out o); return(true); }
// public static bool duk_get_object(IntPtr ctx, int idx, out object o) // { // if (DuktapeDLL.duk_is_null_or_undefined(ctx, idx)) // or check for object? // { // o = null; // return true; // } // var jstype = DuktapeDLL.duk_get_type(ctx, idx); // Debug.LogFormat("duk_get_object({0})", jstype); // switch (jstype) // { // case duk_type_t.DUK_TYPE_STRING: // o = DuktapeDLL.duk_get_string(ctx, idx); // return true; // default: break; // } // return duk_get_cached_object(ctx, idx, out o); // } public static bool duk_get_classvalue_array <T>(IntPtr ctx, int idx, out T[] o) where T : class { if (DuktapeDLL.duk_is_array(ctx, idx)) { var length = DuktapeDLL.duk_unity_get_length(ctx, idx); o = new T[length]; idx = DuktapeDLL.duk_normalize_index(ctx, idx); for (var i = 0U; i < length; i++) { DuktapeDLL.duk_get_prop_index(ctx, idx, i); T e; if (duk_get_classvalue(ctx, -1, out e)) { o[i] = e; } } return(true); } o = null; return(false); }
public void PushProperty(IntPtr ctx, uint index) { this.Push(ctx); // push this DuktapeDLL.duk_get_prop_index(ctx, -1, index); DuktapeDLL.duk_remove(ctx, -2); // remove this }