public static bool duk_retrive_object(IntPtr ctx, string el0) { DuktapeDLL.duk_dup_top(ctx); if (!DuktapeDLL.duk_get_prop_string(ctx, -1, el0)) // [parent, el0] { DuktapeDLL.duk_remove(ctx, -2); return(false); } DuktapeDLL.duk_remove(ctx, -2); return(true); }
public static void duk_begin_namespace(IntPtr ctx, string el) // [parent] { // Debug.LogFormat("begin namespace {0}", DuktapeDLL.duk_get_top(ctx)); if (!DuktapeDLL.duk_get_prop_string(ctx, -1, el)) // [parent, el] { DuktapeDLL.duk_pop(ctx); // [parent] DuktapeDLL.duk_push_object(ctx); // [parent, new_object] DuktapeDLL.duk_dup_top(ctx); // [parent, new_object] DuktapeDLL.duk_put_prop_string(ctx, -3, el); // [parent, el] } }
protected static void duk_begin_special(IntPtr ctx, string name) { DuktapeDLL.duk_push_c_function(ctx, object_private_ctor, 0); // ctor DuktapeDLL.duk_dup(ctx, -1); DuktapeDLL.duk_dup(ctx, -1); var typeValue = new DuktapeFunction(ctx, DuktapeDLL.duk_unity_ref(ctx)); // ctor, ctor DuktapeVM.GetVM(ctx).AddSpecial(name, typeValue); DuktapeDLL.duk_put_prop_string(ctx, -3, name); // ctor DuktapeDLL.duk_push_object(ctx); // ctor, prototype DuktapeDLL.duk_dup_top(ctx); // ctor, prototype, prototype DuktapeDLL.duk_put_prop_string(ctx, -3, "prototype"); // ctor, prototype }
public static bool duk_retrive_object(IntPtr ctx, params string[] els) { DuktapeDLL.duk_dup_top(ctx); for (int i = 1, size = els.Length; i < size; i++) { var el = els[i]; if (!DuktapeDLL.duk_get_prop_string(ctx, -1, el)) // [parent, el] { DuktapeDLL.duk_remove(ctx, -2); return(false); } DuktapeDLL.duk_remove(ctx, -2); } return(true); }
protected static void duk_begin_class(IntPtr ctx, string typename, Type type, DuktapeDLL.duk_c_function ctor) { // Debug.LogFormat("begin class {0}", DuktapeDLL.duk_get_top(ctx)); DuktapeDLL.duk_push_c_function(ctx, ctor, DuktapeDLL.DUK_VARARGS); // [ctor] DuktapeDLL.duk_dup(ctx, -1); // Debug.LogFormat("begin check {0}", DuktapeDLL.duk_get_top(ctx)); DuktapeDLL.duk_dup(ctx, -1); var refid = DuktapeVM.GetVM(ctx).AddExported(type, new DuktapeFunction(ctx, DuktapeDLL.duk_unity_ref(ctx))); DuktapeDLL.duk_push_uint(ctx, refid); DuktapeDLL.duk_put_prop_string(ctx, -3, DuktapeVM.OBJ_PROP_EXPORTED_REFID); // Debug.LogFormat("end check {0}", DuktapeDLL.duk_get_top(ctx)); DuktapeDLL.duk_put_prop_string(ctx, -3, typename); DuktapeDLL.duk_push_object(ctx); // [ctor, prototype] DuktapeDLL.duk_dup_top(ctx); // [ctor, prototype, prototype] DuktapeDLL.duk_push_c_function(ctx, object_dtor, 1); DuktapeDLL.duk_set_finalizer(ctx, -3); // set prototype finalizer DuktapeDLL.duk_put_prop_string(ctx, -3, "prototype"); // [ctor, prototype] }
protected static void duk_begin_class(IntPtr ctx, string typename, Type type, DuktapeDLL.duk_c_function ctor) { // Debug.LogFormat("begin class {0}", DuktapeDLL.duk_get_top(ctx)); DuktapeDLL.duk_push_c_function(ctx, ctor, DuktapeDLL.DUK_VARARGS); // [ctor] DuktapeDLL.duk_dup(ctx, -1); // [ctor ctor] // Debug.LogFormat("begin check {0}", DuktapeDLL.duk_get_top(ctx)); DuktapeDLL.duk_dup(ctx, -1); // [ctor ctor ctor] var ptr = DuktapeDLL.duk_get_heapptr(ctx, -1); var typeid = DuktapeVM.GetVM(ctx).AddExportedType(type, new DuktapeFunction(ctx, DuktapeDLL.duk_unity_ref(ctx), ptr)); DuktapeDLL.duk_unity_set_type_refid(ctx, -1, typeid); // constructor_function.!type == typeid // Debug.LogFormat("end check {0}", DuktapeDLL.duk_get_top(ctx)); DuktapeDLL.duk_put_prop_string(ctx, -3, typename); DuktapeDLL.duk_push_object(ctx); // [ctor, prototype] DuktapeDLL.duk_dup_top(ctx); // [ctor, prototype, prototype] DuktapeDLL.duk_unity_set_type_refid(ctx, -1, typeid); // prototype.!type == typeid DuktapeDLL.duk_push_c_function(ctx, object_dtor, 1); DuktapeDLL.duk_set_finalizer(ctx, -3); // set prototype finalizer DuktapeDLL.duk_put_prop_string(ctx, -3, "prototype"); // [ctor, prototype] }
// 无命名空间, 直接外围对象作为容器 (通常是global) public static void duk_begin_namespace(IntPtr ctx) // [parent] { // Debug.LogFormat("begin namespace {0}", DuktapeDLL.duk_get_top(ctx)); DuktapeDLL.duk_dup_top(ctx); // [parent, parent] }