本文整理汇总了C++中duk_push_object函数的典型用法代码示例。如果您正苦于以下问题:C++ duk_push_object函数的具体用法?C++ duk_push_object怎么用?C++ duk_push_object使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了duk_push_object函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_is_prototype_of
static duk_ret_t test_is_prototype_of(duk_context *ctx, void *udata) {
(void) udata;
prep(ctx);
/* obj0.isPrototypeOf(dummy) -> false, traverses prototype chain of dummy */
duk_eval_string(ctx, "Object.prototype.isPrototypeOf");
duk_dup(ctx, 0);
duk_push_object(ctx);
duk_call_method(ctx, 1);
printf("Object.prototype.isPrototypeOf result: %s\n", duk_safe_to_string(ctx, -1));
duk_pop(ctx);
/* obj0.isPrototypeOf(obj1) -> true, traverses prototype chain of obj1 */
duk_eval_string(ctx, "Object.prototype.isPrototypeOf");
duk_dup(ctx, 0);
duk_dup(ctx, 1);
duk_call_method(ctx, 1);
printf("Object.prototype.isPrototypeOf result: %s\n", duk_safe_to_string(ctx, -1));
duk_pop(ctx);
/* dummy.isPrototypeOf(obj0) -> traverses prototype chain of obj0 and throws */
duk_eval_string(ctx, "Object.prototype.isPrototypeOf");
duk_push_object(ctx);
duk_dup(ctx, 0);
duk_call_method(ctx, 1);
printf("Object.prototype.isPrototypeOf result: %s\n", duk_safe_to_string(ctx, -1));
duk_pop(ctx);
return 0;
}
示例2: duk_push_sphere_bytearray
void
duk_push_sphere_bytearray(duk_context* ctx, bytearray_t* array)
{
duk_push_object(ctx);
duk_push_string(ctx, "bytearray"); duk_put_prop_string(ctx, -2, "\xFF" "sphere_type");
duk_push_pointer(ctx, array); duk_put_prop_string(ctx, -2, "\xFF" "ptr");
duk_push_c_function(ctx, js_ByteArray_finalize, DUK_VARARGS); duk_set_finalizer(ctx, -2);
duk_push_c_function(ctx, js_ByteArray_toString, DUK_VARARGS); duk_put_prop_string(ctx, -2, "toString");
duk_push_c_function(ctx, js_ByteArray_concat, DUK_VARARGS); duk_put_prop_string(ctx, -2, "concat");
duk_push_c_function(ctx, js_ByteArray_slice, DUK_VARARGS); duk_put_prop_string(ctx, -2, "slice");
duk_push_string(ctx, "length"); duk_push_int(ctx, array->size);
duk_def_prop(ctx, -3,
DUK_DEFPROP_HAVE_CONFIGURABLE | 0
| DUK_DEFPROP_HAVE_WRITABLE | 0
| DUK_DEFPROP_HAVE_VALUE);
// return proxy object so we can catch array accesses
duk_push_global_object(ctx);
duk_get_prop_string(ctx, -1, "Proxy");
duk_dup(ctx, -3);
duk_push_object(ctx);
duk_push_c_function(ctx, js_ByteArray_getProp, DUK_VARARGS); duk_put_prop_string(ctx, -2, "get");
duk_push_c_function(ctx, js_ByteArray_setProp, DUK_VARARGS); duk_put_prop_string(ctx, -2, "set");
duk_new(ctx, 2);
duk_remove(ctx, -2);
duk_remove(ctx, -2);
}
示例3: Expose_Light
void Expose_Light(duk_context* ctx)
{
duk_push_object(ctx);
duk_put_function_list(ctx, -1, Light_StaticFunctions);
duk_push_number(ctx, 0);
duk_put_prop_string(ctx, -2, "PointLight");
duk_push_number(ctx, 1);
duk_put_prop_string(ctx, -2, "Spotlight");
duk_push_number(ctx, 2);
duk_put_prop_string(ctx, -2, "DirectionalLight");
duk_push_object(ctx);
duk_put_function_list(ctx, -1, Light_Functions);
DefineProperty(ctx, "ComponentNameChanged", Light_Get_ComponentNameChanged, nullptr);
DefineProperty(ctx, "ParentEntitySet", Light_Get_ParentEntitySet, nullptr);
DefineProperty(ctx, "ParentEntityAboutToBeDetached", Light_Get_ParentEntityAboutToBeDetached, nullptr);
DefineProperty(ctx, "typeName", Light_TypeName, nullptr);
DefineProperty(ctx, "typeId", Light_TypeId, nullptr);
DefineProperty(ctx, "name", Light_Name, Light_SetName_String);
DefineProperty(ctx, "replicated", Light_IsReplicated, Light_SetReplicated_bool);
DefineProperty(ctx, "local", Light_IsLocal, nullptr);
DefineProperty(ctx, "unacked", Light_IsUnacked, nullptr);
DefineProperty(ctx, "updateMode", Light_UpdateMode, Light_SetUpdateMode_AttributeChange__Type);
DefineProperty(ctx, "id", Light_Id, nullptr);
DefineProperty(ctx, "temporary", Light_IsTemporary, Light_SetTemporary_bool);
DefineProperty(ctx, "viewEnabled", Light_ViewEnabled, nullptr);
duk_put_prop_string(ctx, -2, "prototype");
duk_put_global_string(ctx, Light_ID);
}
示例4: duk__push_module_object
static void duk__push_module_object(duk_context *ctx, const char *id, duk_bool_t main) {
duk_push_object(ctx);
/* Set this as the main module, if requested */
if (main) {
duk_push_global_stash(ctx);
duk_dup(ctx, -2);
duk_put_prop_string(ctx, -2, "\xff" "mainModule");
duk_pop(ctx);
}
/* Node.js uses the canonicalized filename of a module for both module.id
* and module.filename. We have no concept of a file system here, so just
* use the module ID for both values.
*/
duk_push_string(ctx, id);
duk_dup(ctx, -1);
duk_put_prop_string(ctx, -3, "filename");
duk_put_prop_string(ctx, -2, "id");
/* module.exports = {} */
duk_push_object(ctx);
duk_put_prop_string(ctx, -2, "exports");
/* module.loaded = false */
duk_push_false(ctx);
duk_put_prop_string(ctx, -2, "loaded");
/* module.require */
duk__push_require_function(ctx, id);
duk_put_prop_string(ctx, -2, "require");
}
示例5: sjs_mod_init
DUK_EXTERNAL duk_ret_t sjs_mod_init(duk_context* ctx) {
duk_push_object(ctx);
duk_put_function_list(ctx, -1, module_funcs);
duk_push_object(ctx);
duk_put_number_list(ctx, -1, module_consts);
duk_put_prop_string(ctx, -2, "c");
return 1;
}
示例6: dukopen_nsp_texture
duk_ret_t dukopen_nsp_texture(duk_context *ctx) {
duk_idx_t idx = duk_push_object(ctx);
duk_idx_t stats_constr = duk_push_c_function(ctx, nsp_texture_constructor, DUK_VARARGS);
duk_idx_t stats_prot = duk_push_object(ctx);
duk_put_function_list(ctx, stats_prot, nsp_texture_methods);
duk_put_prop_string(ctx, stats_constr, "prototype");
duk_put_prop_string(ctx, idx, "Texture");
return 1;
}
示例7: init_binding_worker
static int init_binding_worker(duk_context *ctx) {
duk_push_global_stash(ctx);
duk_push_object(ctx);
duk_put_prop_string(ctx, -2, "comoWorkersCallBack");
duk_pop(ctx);
duk_push_object(ctx);
duk_put_function_list(ctx, -1, como_worker_funcs);
return 1;
}
示例8: dukopen_logger
duk_ret_t dukopen_logger(duk_context *ctx) noexcept
{
dukx_assert_begin(ctx);
duk_push_object(ctx);
duk_push_object(ctx);
duk_put_function_list(ctx, -1, loggerFunctions);
duk_put_prop_string(ctx, -2, "Logger");
dukx_assert_end(ctx, 1);
return 1;
}
示例9: main
int main(int argc, char *argv[]) {
int i, rc;
prg.argc = argc;
prg.argv = argv;
prg.name = argv[1];
duk_context *ctx = duk_create_heap_default();
duk_push_global_object(ctx);
duk_push_object(ctx); /* -> [ ... global obj ] */
sys1(ctx);
for(i=1;i<argc;i++) {
duk_push_string(ctx, argv[i]);
duk_put_prop_index(ctx, -2, i-1);
}
duk_push_number(ctx, argc-1);
duk_put_prop_string(ctx, -2, "argc");
duk_put_prop_string(ctx, -2, "Sys1"); /* -> [ ... global ] */
duk_push_object(ctx); /* -> [ ... global obj ] */
prg1(ctx);
duk_put_prop_string(ctx, -2, "Prg1"); /* -> [ ... global ] */
prg_push_modsearch(ctx);
duk_pop(ctx);
prg_parse_appfile(&prg);
// push file
duk_push_lstring(ctx, prg.main->buf, prg.main->size);
duk_push_string(ctx, argv[1]);
// execute file (compile + call)
prg_register(&prg);
rc = duk_safe_call(ctx, prg_wrapped_compile_execute, 2 /*nargs*/, 1 /*nret*/);
if (rc != DUK_EXEC_SUCCESS) {
print_error(ctx, stderr);
exit(2);
}
duk_pop(ctx); /* pop eval result */
duk_destroy_heap(ctx);
return prg.status;
}
示例10: duk_create_heap_default
StyleContext::StyleContext() {
m_ctx = duk_create_heap_default();
//// Create global geometry constants
// TODO make immutable
duk_push_number(m_ctx, GeometryType::points);
duk_put_global_string(m_ctx, "point");
duk_push_number(m_ctx, GeometryType::lines);
duk_put_global_string(m_ctx, "line");
duk_push_number(m_ctx, GeometryType::polygons);
duk_put_global_string(m_ctx, "polygon");
//// Create global 'feature' object
// Get Proxy constructor
// -> [cons]
duk_eval_string(m_ctx, "Proxy");
// Add feature object
// -> [cons, { __obj: this }]
duk_idx_t featureObj = duk_push_object(m_ctx);
duk_push_pointer(m_ctx, this);
duk_put_prop_string(m_ctx, featureObj, INSTANCE_ID);
// Add handler object
// -> [cons, {...}, { get: func, has: func }]
duk_idx_t handlerObj = duk_push_object(m_ctx);
// Add 'get' property to handler
duk_push_c_function(m_ctx, jsGetProperty, 3 /*nargs*/);
duk_put_prop_string(m_ctx, handlerObj, "get");
// Add 'has' property to handler
duk_push_c_function(m_ctx, jsHasProperty, 2 /*nargs*/);
duk_put_prop_string(m_ctx, handlerObj, "has");
// Call proxy constructor
// [cons, feature, handler ] -> [obj|error]
if (duk_pnew(m_ctx, 2) == 0) {
// put feature proxy object in global scope
if (!duk_put_global_string(m_ctx, "feature")) {
LOGE("Initialization failed");
}
} else {
LOGE("Failure: %s", duk_safe_to_string(m_ctx, -1));
duk_pop(m_ctx);
}
DUMP("init\n");
}
示例11: Expose_IAssetTransfer
void Expose_IAssetTransfer(duk_context* ctx)
{
duk_push_object(ctx);
duk_push_object(ctx);
duk_put_function_list(ctx, -1, IAssetTransfer_Functions);
DefineProperty(ctx, "asset", IAssetTransfer_Get_asset, IAssetTransfer_Set_asset);
DefineProperty(ctx, "source", IAssetTransfer_Get_source, IAssetTransfer_Set_source);
DefineProperty(ctx, "assetType", IAssetTransfer_Get_assetType, IAssetTransfer_Set_assetType);
DefineProperty(ctx, "internalResourceName", IAssetTransfer_Get_internalResourceName, IAssetTransfer_Set_internalResourceName);
DefineProperty(ctx, "Downloaded", IAssetTransfer_Get_Downloaded, nullptr);
DefineProperty(ctx, "Succeeded", IAssetTransfer_Get_Succeeded, nullptr);
DefineProperty(ctx, "Failed", IAssetTransfer_Get_Failed, nullptr);
duk_put_prop_string(ctx, -2, "prototype");
duk_put_global_string(ctx, IAssetTransfer_ID);
}
示例12: duk_push_object
duk_ret_t JsLibrarian::Constructor(duk_context* duktapeContext)
{
try {
if (duk_get_top(duktapeContext) != 0) JavaScriptHelper::Throw(duktapeContext, "No arguments for Librarian constructor expected");
if (duk_is_constructor_call(duktapeContext)) duk_push_this(duktapeContext);
else duk_push_object(duktapeContext);
duk_push_pointer(duktapeContext, new JsLibrarian);
duk_put_prop_string(duktapeContext, -2, "__Ptr");
duk_push_c_function(duktapeContext, JsLibrarian::Destructor, 1);
duk_set_finalizer(duktapeContext, -2);
duk_push_c_function(duktapeContext, JsLibrarian::Files, DUK_VARARGS);
duk_put_prop_string(duktapeContext, -2, "Files");
duk_push_c_function(duktapeContext, JsLibrarian::DependencyCheck, DUK_VARARGS);
duk_put_prop_string(duktapeContext, -2, "DependencyCheck");
duk_push_c_function(duktapeContext, JsLibrarian::Output, DUK_VARARGS);
duk_put_prop_string(duktapeContext, -2, "Output");
duk_push_c_function(duktapeContext, JsLibrarian::BeforeLink, DUK_VARARGS);
duk_put_prop_string(duktapeContext, -2, "BeforeLink");
duk_push_c_function(duktapeContext, JsLibrarian::Create, DUK_VARARGS);
duk_put_prop_string(duktapeContext, -2, "Create");
return 1;
}
catch (std::exception& e) {
JavaScriptHelper::Throw(duktapeContext, e.what());
}
}
示例13: test
static duk_ret_t test(duk_context *ctx) {
duk_push_object(ctx); /* [ ... obj ] */
duk_push_int(ctx, 42); /* [ ... obj 42 ] */
duk_put_prop_string(ctx, -2, "meaningOfLife"); /* [ ... obj ] */
/* compaction has no external impact */
duk_compact(ctx, -1); /* [ ... obj ] */
duk_dup_top(ctx);
printf("%s\n", duk_json_encode(ctx, -1));
duk_pop(ctx);
/* compaction doesn't prevent new properties from being added */
duk_push_string(ctx, "bar"); /* [ ... obj "bar" ] */
duk_put_prop_string(ctx, -2, "foo"); /* [ ... obj ] */
duk_dup_top(ctx);
printf("%s\n", duk_json_encode(ctx, -1));
duk_pop(ctx);
/* compaction can be done multiple times */
duk_compact(ctx, -1); /* [ ... obj ] */
duk_dup_top(ctx);
printf("%s\n", duk_json_encode(ctx, -1));
duk_pop(ctx);
return 0;
}
示例14: NativeInfoGetter
/*
* Returns information about this pin
*/
static int NativeInfoGetter(duk_context* ctx)
{
int idx;
uint32_t pin;
const AJS_IO_Info* info;
duk_push_this(ctx);
pin = GetPinId(ctx, -1, 0);
duk_pop(ctx);
info = AJS_TargetIO_GetInfo(pin);
if (!info) {
duk_error(ctx, DUK_ERR_INTERNAL_ERROR, "Undefined I/O pin%d", pin);
return 0;
}
duk_push_string(ctx, ", ");
idx = duk_push_object(ctx);
duk_push_int(ctx, info->physicalPin);
duk_put_prop_string(ctx, idx, "physicalPin");
duk_push_string(ctx, info->schematicId);
duk_put_prop_string(ctx, idx, "schematicId");
duk_push_string(ctx, info->datasheetId);
duk_put_prop_string(ctx, idx, "datasheetId");
duk_push_string(ctx, info->description);
duk_put_prop_string(ctx, idx, "description");
/*
* Return the object we just created
*/
return 1;
}
示例15: test_string
static duk_ret_t test_string(duk_context *ctx, void *udata) {
duk_idx_t i, n;
(void) udata;
duk_push_undefined(ctx);
duk_push_null(ctx);
duk_push_true(ctx);
duk_push_false(ctx);
duk_push_string(ctx, "");
duk_push_string(ctx, "foo");
duk_push_lstring(ctx, "foo\0bar", 7);
duk_push_string(ctx, "\xe1\x88\xb4xyz"); /* 4 chars, first char utf-8 encoded U+1234 */
duk_push_nan(ctx);
duk_push_object(ctx);
n = duk_get_top(ctx);
printf("top: %ld\n", (long) n);
for (i = 0; i <= n; i++) {
printf("index %ld: ", (long) i);
dump((const unsigned char *) duk_get_string_default(ctx, i, "default"));
}
return 0;
}