本文整理汇总了C++中duk_push_this函数的典型用法代码示例。如果您正苦于以下问题:C++ duk_push_this函数的具体用法?C++ duk_push_this怎么用?C++ duk_push_this使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了duk_push_this函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: File_ReadText
static int File_ReadText(duk_context* ctx)
{
duk_push_this(ctx);
File* file = js_to_class_instance<File>(ctx, -1, 0);
String text;
file->ReadText(text);
duk_push_string(ctx, text.CString());
return 1;
}
示例2: duk_bi_logger_constructor
/* Constructor */
DUK_INTERNAL duk_ret_t duk_bi_logger_constructor(duk_context *ctx) {
duk_hthread *thr = (duk_hthread *) ctx;
duk_idx_t nargs;
/* Calling as a non-constructor is not meaningful. */
if (!duk_is_constructor_call(ctx)) {
return DUK_RET_TYPE_ERROR;
}
nargs = duk_get_top(ctx);
duk_set_top(ctx, 1);
duk_push_this(ctx);
/* [ name this ] */
if (nargs == 0) {
/* Automatic defaulting of logger name from caller. This would
* work poorly with tail calls, but constructor calls are currently
* never tail calls, so tail calls are not an issue now.
*/
if (thr->callstack_top >= 2) {
duk_activation *act_caller = thr->callstack + thr->callstack_top - 2;
duk_hobject *func_caller;
func_caller = DUK_ACT_GET_FUNC(act_caller);
if (func_caller) {
/* Stripping the filename might be a good idea
* ("/foo/bar/quux.js" -> logger name "quux"),
* but now used verbatim.
*/
duk_push_hobject(ctx, func_caller);
duk_get_prop_stridx(ctx, -1, DUK_STRIDX_FILE_NAME);
duk_replace(ctx, 0);
}
}
}
/* the stack is unbalanced here on purpose; we only rely on the
* initial two values: [ name this ].
*/
if (duk_is_string(ctx, 0)) {
duk_dup(ctx, 0);
duk_put_prop_stridx(ctx, 1, DUK_STRIDX_LC_N);
} else {
/* don't set 'n' at all, inherited value is used as name */
}
duk_compact(ctx, 1);
return 0; /* keep default instance */
}
示例3: js_Font_clone
static duk_ret_t
js_Font_clone(duk_context* ctx)
{
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);
// TODO: actually clone font in Font:clone()
duk_push_sphere_font(ctx, font);
return 1;
}
示例4: gumjs_stalker_from_args
static GumDukStalker *
gumjs_stalker_from_args (const GumDukArgs * args)
{
duk_context * ctx = args->ctx;
GumDukStalker * self;
duk_push_this (ctx);
self = _gum_duk_require_data (ctx, -1);
duk_pop (ctx);
return self;
}
示例5: NativeGetAllProps
static int NativeGetAllProps(duk_context* ctx)
{
if (!duk_is_string(ctx, 0)) {
duk_error(ctx, DUK_ERR_TYPE_ERROR, "First argument must be the interface name");
}
duk_push_c_lightfunc(ctx, AJS_MarshalMethodCall, 1, 0, 0);
duk_push_this(ctx);
MessageSetup(ctx, &AJ_PropertiesIface[0][1], "GetAll", NULL, AJ_MSG_METHOD_CALL);
duk_dup(ctx, 0);
duk_call_method(ctx, 1);
return 1;
}
示例6: js_Logger_write
static duk_ret_t
js_Logger_write(duk_context* ctx)
{
const char* text = duk_to_string(ctx, 0);
logger_t* logger;
duk_push_this(ctx);
logger = duk_require_sphere_obj(ctx, -1, "Logger");
write_log_line(logger, NULL, text);
return 0;
}
示例7: js_Sound_reset
static duk_ret_t
js_Sound_reset(duk_context* ctx)
{
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);
seek_sound(sound, 0);
play_sound(sound);
return 0;
}
示例8: Light_SetShadowBias
static int Light_SetShadowBias(duk_context* ctx)
{
float constantBias = (float) duk_to_number(ctx, 0);
float slopeScaledBias = (float) duk_to_number(ctx, 1);
BiasParameters bparms(constantBias, slopeScaledBias);
duk_push_this(ctx);
Light* light = js_to_class_instance<Light>(ctx, -1, 0);
light->SetShadowBias(bparms);
return 0;
}
示例9: duk_bi_error_prototype_to_string
int duk_bi_error_prototype_to_string(duk_context *ctx) {
/* FIXME: optimize with more direct internal access */
duk_push_this(ctx);
if (!duk_is_object(ctx, -1)) {
goto type_error;
}
/* [ ... this ] */
duk_get_prop_stridx(ctx, -1, DUK_STRIDX_NAME);
if (duk_is_undefined(ctx, -1)) {
duk_pop(ctx);
duk_push_string(ctx, "Error");
} else {
duk_to_string(ctx, -1);
}
/* [ ... this name ] */
/* FIXME: Are steps 6 and 7 in E5 Section 15.11.4.4 duplicated by
* accident or are they actually needed? The first ToString()
* could conceivably return 'undefined'.
*/
duk_get_prop_stridx(ctx, -2, DUK_STRIDX_MESSAGE);
if (duk_is_undefined(ctx, -1)) {
duk_pop(ctx);
duk_push_string(ctx, "");
} else {
duk_to_string(ctx, -1);
}
/* [ ... this name message ] */
if (duk_get_length(ctx, -2) == 0) {
/* name is empty -> return message */
return 1;
}
if (duk_get_length(ctx, -1) == 0) {
/* message is empty -> return name */
duk_pop(ctx);
return 1;
}
duk_push_string(ctx, ": ");
duk_insert(ctx, -2); /* ... name ': ' message */
duk_concat(ctx, 3);
return 1;
type_error:
return DUK_RET_TYPE_ERROR;
}
示例10: 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);
font = duk_require_sphere_obj(ctx, -1, "Font");
duk_pop(ctx);
duk_push_int(ctx, get_text_width(font, text));
return 1;
}
示例11: 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;
}
示例12: 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;
}
示例13: 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);
font = duk_require_sphere_obj(ctx, -1, "Font");
duk_pop(ctx);
duk_push_sphere_image(ctx, get_glyph_image(font, cp));
return 1;
}
示例14: 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;
}
示例15: js_Logger_beginBlock
static duk_ret_t
js_Logger_beginBlock(duk_context* ctx)
{
const char* title = duk_to_string(ctx, 0);
logger_t* logger;
duk_push_this(ctx);
logger = duk_require_sphere_obj(ctx, -1, "Logger");
if (!begin_log_block(logger, title))
duk_error_ni(ctx, -1, DUK_ERR_ERROR, "Log:beginBlock(): Failed to create new log block");
return 0;
}