本文整理汇总了C++中duk_get_prop_string函数的典型用法代码示例。如果您正苦于以下问题:C++ duk_get_prop_string函数的具体用法?C++ duk_get_prop_string怎么用?C++ duk_get_prop_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了duk_get_prop_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dump_error
void dump_error(duk_context *ctx) {
duk_dup(ctx, -1);
printf("ToString(error): %s\n", duk_to_string(ctx, -1));
duk_pop(ctx);
duk_get_prop_string(ctx, -1, "name");
printf("name: %s\n", duk_to_string(ctx, -1));
duk_pop(ctx);
duk_get_prop_string(ctx, -1, "message");
printf("message: %s\n", duk_to_string(ctx, -1));
duk_pop(ctx);
/* 'code' is no longer set, test that it reads back as 'undefined' */
duk_get_prop_string(ctx, -1, "code");
printf("code: %s\n", duk_to_string(ctx, -1));
duk_pop(ctx);
duk_get_prop_string(ctx, -1, "fileName");
printf("fileName is a string: %d\n", (int) duk_is_string(ctx, -1));
duk_pop(ctx);
duk_get_prop_string(ctx, -1, "lineNumber");
printf("lineNumber: %ld\n", (long) duk_get_int(ctx, -1));
duk_pop(ctx);
/* 'isNative' has also been removed, check that it reads back as 'undefined' */
duk_get_prop_string(ctx, -1, "isNative");
printf("isNative: %s\n", duk_to_string(ctx, -1));
duk_pop(ctx);
}
示例2: nsp_texture_draw_line
// ====== Xtase drawing routines ======
duk_ret_t nsp_texture_draw_line(duk_context *ctx) {
int x1 = duk_require_int(ctx, 0);
int y1 = duk_require_int(ctx, 1);
int x2 = duk_require_int(ctx, 2);
int y2 = duk_require_int(ctx, 3);
uint16_t color = duk_require_int(ctx, 4);
duk_push_this(ctx);
duk_get_prop_string(ctx, -1, "width");
int w = duk_require_int(ctx, -1);
duk_pop(ctx);
duk_get_prop_string(ctx, -1, "height");
int h = duk_require_int(ctx, -1);
duk_pop(ctx);
if (w <= 0 || h <= 0) {
duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "width and height must be positive");
duk_throw(ctx);
}
duk_get_prop_string(ctx, -1, "bitmap");
size_t size;
uint16_t *bitmap = duk_get_buffer(ctx, -1, &size);
if (bitmap == NULL) {
duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap pointer is NULL");
duk_throw(ctx);
}
FbDev* fb = (FbDev*)malloc( 1 * sizeof(FbDev) );
fb->width = w;
fb->height = h;
fb->fb_size = w * h;
fb->fb = bitmap;
drawLine(x1,y1,x2,y2,color,fb);
free(fb);
return 0;
}
示例3: dump_error
void dump_error(duk_context *ctx) {
duk_dup(ctx, -1);
printf("ToString(error): %s\n", duk_to_string(ctx, -1));
duk_pop(ctx);
duk_get_prop_string(ctx, -1, "name");
printf("name: %s\n", duk_to_string(ctx, -1));
duk_pop(ctx);
duk_get_prop_string(ctx, -1, "message");
printf("message: %s\n", duk_to_string(ctx, -1));
duk_pop(ctx);
duk_get_prop_string(ctx, -1, "code");
printf("code: %d\n", duk_get_int(ctx, -1));
duk_pop(ctx);
duk_get_prop_string(ctx, -1, "fileName");
printf("fileName: %s\n", duk_to_string(ctx, -1));
duk_pop(ctx);
duk_get_prop_string(ctx, -1, "lineNumber");
printf("lineNumber: %d\n", duk_get_int(ctx, -1));
duk_pop(ctx);
duk_get_prop_string(ctx, -1, "isNative");
printf("isNative: %s\n", duk_to_string(ctx, -1));
duk_pop(ctx);
}
示例4: js_Font_drawTextBox
static duk_ret_t
js_Font_drawTextBox(duk_context* ctx)
{
int x = duk_require_int(ctx, 0);
int y = duk_require_int(ctx, 1);
int w = duk_require_int(ctx, 2);
int h = duk_require_int(ctx, 3);
int offset = duk_require_int(ctx, 4);
const char* text = duk_to_string(ctx, 5);
font_t* font;
int line_height;
const char* line_text;
color_t mask;
int num_lines;
int i;
duk_push_this(ctx);
font = duk_require_sphere_obj(ctx, -1, "Font");
duk_get_prop_string(ctx, -1, "\xFF" "color_mask"); mask = duk_require_sphere_color(ctx, -1); duk_pop(ctx);
duk_pop(ctx);
if (!screen_is_skipframe(g_screen)) {
duk_push_c_function(ctx, js_Font_wordWrapString, DUK_VARARGS);
duk_push_this(ctx);
duk_push_string(ctx, text);
duk_push_int(ctx, w);
duk_call_method(ctx, 2);
duk_get_prop_string(ctx, -1, "length"); num_lines = duk_get_int(ctx, -1); duk_pop(ctx);
line_height = get_font_line_height(font);
for (i = 0; i < num_lines; ++i) {
duk_get_prop_index(ctx, -1, i); line_text = duk_get_string(ctx, -1); duk_pop(ctx);
draw_text(font, mask, x + offset, y, TEXT_ALIGN_LEFT, line_text);
y += line_height;
}
duk_pop(ctx);
}
return 0;
}
示例5: js_Font_getStringWidth
static duk_ret_t
js_Font_getStringWidth(duk_context* ctx)
{
const char* text = duk_to_string(ctx, 0);
font_t* font;
duk_push_this(ctx);
duk_get_prop_string(ctx, -1, "\xFF" "ptr"); font = duk_get_pointer(ctx, -1); duk_pop(ctx);
duk_pop(ctx);
duk_push_int(ctx, get_text_width(font, text));
return 1;
}
示例6: js_Font_getStringHeight
static duk_ret_t
js_Font_getStringHeight(duk_context* ctx)
{
const char* text = duk_to_string(ctx, 0);
int width = duk_require_int(ctx, 1);
font_t* font;
int num_lines;
duk_push_this(ctx);
duk_get_prop_string(ctx, -1, "\xFF" "ptr"); font = duk_get_pointer(ctx, -1); duk_pop(ctx);
duk_pop(ctx);
duk_push_c_function(ctx, js_Font_wordWrapString, DUK_VARARGS);
duk_push_this(ctx);
duk_push_string(ctx, text);
duk_push_int(ctx, width);
duk_call_method(ctx, 2);
duk_get_prop_string(ctx, -1, "length"); num_lines = duk_get_int(ctx, -1); duk_pop(ctx);
duk_pop(ctx);
duk_push_int(ctx, get_font_line_height(font) * num_lines);
return 1;
}
示例7: js_Font_getCharacterImage
static duk_ret_t
js_Font_getCharacterImage(duk_context* ctx)
{
int cp = duk_require_int(ctx, 0);
font_t* font;
duk_push_this(ctx);
duk_get_prop_string(ctx, -1, "\xFF" "ptr"); font = duk_get_pointer(ctx, -1); duk_pop(ctx);
duk_pop(ctx);
duk_push_sphere_image(ctx, get_glyph_image(font, cp));
return 1;
}
示例8: duk_module_node_init
void duk_module_node_init(duk_context *ctx) {
/*
* Stack: [ ... options ] => [ ... ]
*/
duk_idx_t options_idx;
duk_require_object_coercible(ctx, -1); /* error before setting up requireCache */
options_idx = duk_require_normalize_index(ctx, -1);
/* Initialize the require cache to a fresh object. */
duk_push_global_stash(ctx);
duk_push_object(ctx);
duk_put_prop_string(ctx, -2, "\xff" "requireCache");
duk_pop(ctx);
/* Stash callbacks for later use. User code can overwrite them later
* on directly by accessing the global stash.
*/
duk_push_global_stash(ctx);
duk_get_prop_string(ctx, options_idx, "resolve");
duk_require_function(ctx, -1);
duk_put_prop_string(ctx, -2, "\xff" "modResolve");
duk_get_prop_string(ctx, options_idx, "load");
duk_require_function(ctx, -1);
duk_put_prop_string(ctx, -2, "\xff" "modLoad");
duk_pop(ctx);
/* register `require` as a global function */
duk_push_global_object(ctx);
duk_push_string(ctx, "require");
duk__push_require_function(ctx, "");
duk_def_prop(ctx, -3, DUK_DEFPROP_HAVE_VALUE |
DUK_DEFPROP_SET_WRITABLE |
DUK_DEFPROP_SET_CONFIGURABLE);
duk_pop(ctx);
duk_pop(ctx); /* pop argument */
}
示例9: PushServiceCallback
/*
* If there is a callback registered for this interface pushes the function onto the stack
*/
static int PushServiceCallback(duk_context* ctx, const char* iface)
{
AJS_GetGlobalStashObject(ctx, "serviceCB");
duk_get_prop_string(ctx, -1, iface);
duk_remove(ctx, -2);
if (duk_is_callable(ctx, -1)) {
return 1;
} else {
duk_pop(ctx);
return 0;
}
}
示例10: js_Sound_setVolume
static duk_ret_t
js_Sound_setVolume(duk_context* ctx)
{
float new_gain = duk_require_int(ctx, 0);
sound_t* sound;
duk_push_this(ctx);
duk_get_prop_string(ctx, -1, "\xFF" "ptr"); sound = duk_get_pointer(ctx, -1); duk_pop(ctx);
duk_pop(ctx);
set_sound_gain(sound, (float)new_gain / 255);
return 0;
}
示例11: js_Sound_setRepeat
static duk_ret_t
js_Sound_setRepeat(duk_context* ctx)
{
bool is_looped = duk_require_boolean(ctx, 0);
sound_t* sound;
duk_push_this(ctx);
duk_get_prop_string(ctx, -1, "\xFF" "ptr"); sound = duk_get_pointer(ctx, -1); duk_pop(ctx);
duk_pop(ctx);
set_sound_looping(sound, is_looped);
return 0;
}
示例12: dukzip_require_unz
static unzFile dukzip_require_unz(duk_context *ctx, int index) {
unzFile result;
duk_get_prop_string(ctx, index, ZIPHANDLE_PROP);
result = duk_get_pointer(ctx, -1);
duk_pop(ctx);
if (!result) {
duk_error(ctx, DUK_ERR_TYPE_ERROR, "Expected dukzip archive at index %d", index);
return NULL;
}
return result;
}
示例13: js_Sound_setPitch
static duk_ret_t
js_Sound_setPitch(duk_context* ctx)
{
float new_pitch = duk_require_number(ctx, 0);
sound_t* sound;
duk_push_this(ctx);
duk_get_prop_string(ctx, -1, "\xFF" "ptr"); sound = duk_get_pointer(ctx, -1); duk_pop(ctx);
duk_pop(ctx);
set_sound_pitch(sound, new_pitch);
return 0;
}
示例14: duk__console_log_helper
static duk_ret_t duk__console_log_helper(duk_context *ctx, const char *error_name) {
duk_uint_t flags = (duk_uint_t) duk_get_current_magic(ctx);
FILE *output = (flags & DUK_CONSOLE_STDOUT_ONLY) ? stdout : stderr;
duk_idx_t n = duk_get_top(ctx);
duk_idx_t i;
duk_get_global_string(ctx, "console");
duk_get_prop_string(ctx, -1, "format");
for (i = 0; i < n; i++) {
if (duk_check_type_mask(ctx, i, DUK_TYPE_MASK_OBJECT)) {
/* Slow path formatting. */
duk_dup(ctx, -1); /* console.format */
duk_dup(ctx, i);
duk_call(ctx, 1);
duk_replace(ctx, i); /* arg[i] = console.format(arg[i]); */
}
}
duk_pop_2(ctx);
duk_push_string(ctx, " ");
duk_insert(ctx, 0);
duk_join(ctx, n);
if (error_name) {
duk_push_error_object(ctx, DUK_ERR_ERROR, "%s", duk_require_string(ctx, -1));
duk_push_string(ctx, "name");
duk_push_string(ctx, error_name);
duk_def_prop(ctx, -3, DUK_DEFPROP_FORCE | DUK_DEFPROP_HAVE_VALUE); /* to get e.g. 'Trace: 1 2 3' */
duk_get_prop_string(ctx, -1, "stack");
}
fprintf(output, "%s\n", duk_to_string(ctx, -1));
if (flags & DUK_CONSOLE_FLUSH) {
fflush(output);
}
return 0;
}
示例15: GetBinding
static BindingInfo * GetBinding( duk_context * ctx )
{
duk_push_global_stash( ctx );
duk_get_prop_string( ctx, -1, DUKBIND_BINDING_NAME );
duk_size_t buffer_size;
void * buffer = duk_to_buffer( ctx, -1, &buffer_size);
dukbind_assert( buffer_size == sizeof( BindingInfo * ), "Invalid buffer size" );
duk_pop_2( ctx );
return *reinterpret_cast<BindingInfo**>( buffer );
}