本文整理汇总了C++中duk_safe_to_string函数的典型用法代码示例。如果您正苦于以下问题:C++ duk_safe_to_string函数的具体用法?C++ duk_safe_to_string怎么用?C++ duk_safe_to_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了duk_safe_to_string函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: duk_android_log_print
static duk_ret_t duk_android_log_print(duk_context *ctx) {
int n = duk_get_top(ctx);
switch (n) {
case 1:
LOGD("ScriptEngine", "%s", duk_safe_to_string(ctx, 0));
break;
case 2:
LOGD("ScriptEngine", "%s %s", duk_safe_to_string(ctx, 0),
duk_safe_to_string(ctx, 1));
break;
case 3:
LOGD("ScriptEngine", "%s %s %s", duk_safe_to_string(ctx, 0),
duk_safe_to_string(ctx, 1), duk_safe_to_string(ctx, 2));
break;
case 4: {
LOGD("ScriptEngine", "%s %s %s %s", duk_safe_to_string(ctx, 0),
duk_safe_to_string(ctx, 1), duk_safe_to_string(ctx, 2),
duk_safe_to_string(ctx, 3));
}
break;
case 0: {
LOGD("ScriptEngine", "\n");
}
break;
default: {
LOGW("ScriptEngine",
"too many args %d to print, javascript print only support less than 4 args\n",
n);
}
break;
}
return 0;
}
开发者ID:ewrfedf,项目名称:DuktapeJava,代码行数:33,代码来源:DuktapeEngine.c
示例2: main
int main(int argc, const char *argv[]) {
duk_context *ctx = NULL;
ctx = duk_create_heap_default();
if (!ctx) {
printf("Failed to create a Duktape heap.\n");
exit(1);
}
duk_push_global_object(ctx);
duk_push_c_function(ctx, native_prime_check, 2 /*nargs*/);
duk_put_prop_string(ctx, -2, "primeCheckNative");
if (duk_peval_file(ctx, "prime.js") != 0) {
printf("Error: %s\n", duk_safe_to_string(ctx, -1));
goto finished;
}
duk_pop(ctx); /* ignore result */
duk_get_prop_string(ctx, -1, "primeTest");
if (duk_pcall(ctx, 0) != 0) {
printf("Error: %s\n", duk_safe_to_string(ctx, -1));
}
duk_pop(ctx); /* ignore result */
finished:
duk_destroy_heap(ctx);
exit(0);
}
开发者ID:3009420,项目名称:civetweb,代码行数:30,代码来源:primecheck.c
示例3: sjs_vm_eval_code
DUK_EXTERNAL int sjs_vm_eval_code(const sjs_vm_t* vm, const char* filename, const char* code, size_t len, FILE* foutput, FILE* ferror) {
int r;
assert(vm);
duk_context* ctx = vm->ctx;
duk_push_pointer(ctx, (void *) code);
duk_push_uint(ctx, len);
duk_push_string(ctx, filename);
r = duk_safe_call(ctx, sjs__compile_execute, 3 /*nargs*/, 1 /*nret*/);
if (r != DUK_EXEC_SUCCESS) {
if (ferror) {
duk_safe_call(ctx, sjs__get_error_stack, 1 /*nargs*/, 1 /*nrets*/);
fprintf(ferror, "%s\n", duk_safe_to_string(ctx, -1));
fflush(ferror);
}
} else {
if (foutput) {
fprintf(foutput, "= %s\n", duk_safe_to_string(ctx, -1));
fflush(foutput);
}
}
duk_pop(ctx);
return r;
}
开发者ID:cjihrig,项目名称:sjs,代码行数:27,代码来源:vm.c
示例4: 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;
}
开发者ID:GarethNelson,项目名称:duktape,代码行数:31,代码来源:test-dev-prototype-loop.c
示例5: main
int main(int argc, const char *argv[]) {
duk_context *ctx = NULL;
char line[4096];
size_t idx;
int ch;
(void) argc; (void) argv;
ctx = duk_create_heap_default();
if (!ctx) {
printf("Failed to create a Duktape heap.\n");
exit(1);
}
push_file_as_string(ctx, "process.js");
if (duk_peval(ctx) != 0) {
printf("Error: %s\n", duk_safe_to_string(ctx, -1));
goto finished;
}
duk_pop(ctx); /* ignore result */
memset(line, 0, sizeof(line));
idx = 0;
for (;;) {
if (idx >= sizeof(line)) {
printf("Line too long\n");
exit(1);
}
ch = fgetc(stdin);
if (ch == 0x0a) {
line[idx++] = '\0';
duk_push_global_object(ctx);
duk_get_prop_string(ctx, -1 /*index*/, "processLine");
duk_push_string(ctx, line);
if (duk_pcall(ctx, 1 /*nargs*/) != 0) {
printf("Error: %s\n", duk_safe_to_string(ctx, -1));
} else {
printf("%s\n", duk_safe_to_string(ctx, -1));
}
duk_pop(ctx); /* pop result/error */
idx = 0;
} else if (ch == EOF) {
break;
} else {
line[idx++] = (char) ch;
}
}
finished:
duk_destroy_heap(ctx);
exit(0);
}
开发者ID:GarethNelson,项目名称:duktape,代码行数:56,代码来源:processlines.c
示例6: test
void test(duk_context *ctx) {
duk_int_t rc;
/* From API doc */
duk_push_string(ctx, "print('Hello world!'); 123;");
duk_eval(ctx);
printf("return value is: %lf\n", duk_get_number(ctx, -1));
duk_pop(ctx);
/* Function expression */
duk_push_string(ctx, "(function adder(x,y) { return x+y; })");
duk_eval(ctx); /* [ func ] */
duk_push_int(ctx, 123);
duk_push_int(ctx, 234);
duk_call(ctx, 2); /* [ func 123 234 ] -> [ result ] */
printf("adder(123, 234) -> %lf\n", duk_get_number(ctx, -1));
duk_pop(ctx);
/* Protected eval with success */
duk_push_string(ctx, "print('Hello world!'); 123;");
rc = duk_peval(ctx);
printf("return value is: %s (rc=%d)\n", duk_safe_to_string(ctx, -1), (int) rc);
duk_pop(ctx);
/* Protected eval with failure */
duk_push_string(ctx, "throw new Error('eval error');");
rc = duk_peval(ctx);
printf("return value is: %s (rc=%d)\n", duk_safe_to_string(ctx, -1), (int) rc);
duk_pop(ctx);
/* Protected eval with syntax error */
duk_push_string(ctx, "obj = {");
rc = duk_peval(ctx);
printf("return value is: %s (rc=%d)\n", duk_safe_to_string(ctx, -1), (int) rc);
duk_pop(ctx);
/* Plain eval with no result */
printf("top=%ld\n", (long) duk_get_top(ctx));
duk_push_string(ctx, "print('doing eval');");
duk_eval_noresult(ctx);
/* Protected eval with no result, no error */
printf("top=%ld\n", (long) duk_get_top(ctx));
duk_push_string(ctx, "print('doing peval');");
rc = duk_peval_noresult(ctx);
printf("rc=%d\n", (int) rc);
/* Protected eval with no result, syntax error */
printf("top=%ld\n", (long) duk_get_top(ctx));
duk_push_string(ctx, "print('doing peval'); obj = {");
rc = duk_peval_noresult(ctx);
printf("rc=%d\n", (int) rc);
printf("top: %ld\n", (long) duk_get_top(ctx));
}
开发者ID:BrandonTheHamm,项目名称:duktape,代码行数:55,代码来源:test-eval.c
示例7: LOGE
bool StyleContext::evalFunction(FunctionID id) {
// Get all functions (array) in context
if (!duk_get_global_string(m_ctx, FUNC_ID)) {
LOGE("EvalFilterFn - functions array not initialized");
duk_pop(m_ctx); // pop [undefined] sitting at stack top
return false;
}
// Get function at index `id` from functions array, put it at stack top
if (!duk_get_prop_index(m_ctx, -1, id)) {
LOGE("EvalFilterFn - function %d not set", id);
duk_pop(m_ctx); // pop "undefined" sitting at stack top
duk_pop(m_ctx); // pop functions (array) now sitting at stack top
return false;
}
// pop fns array
duk_remove(m_ctx, -2);
// call popped function (sitting at stack top), evaluated value is put on stack top
if (duk_pcall(m_ctx, 0) != 0) {
LOGE("EvalFilterFn: %s", duk_safe_to_string(m_ctx, -1));
duk_pop(m_ctx);
return false;
}
return true;
}
开发者ID:NabilNoaman,项目名称:tangram-es,代码行数:28,代码来源:styleContext.cpp
示例8: duk_push_array
bool StyleContext::setFunctions(const std::vector<std::string>& _functions) {
auto arr_idx = duk_push_array(m_ctx);
int id = 0;
bool ok = true;
for (auto& function : _functions) {
duk_push_string(m_ctx, function.c_str());
duk_push_string(m_ctx, "");
if (duk_pcompile(m_ctx, DUK_COMPILE_FUNCTION) == 0) {
duk_put_prop_index(m_ctx, arr_idx, id);
} else {
LOGW("Compile failed: %s\n%s\n---",
duk_safe_to_string(m_ctx, -1),
function.c_str());
duk_pop(m_ctx);
ok = false;
}
id++;
}
if (!duk_put_global_string(m_ctx, FUNC_ID)) {
LOGE("'fns' object not set");
}
DUMP("setFunctions\n");
return ok;
}
开发者ID:NabilNoaman,项目名称:tangram-es,代码行数:30,代码来源:styleContext.cpp
示例9: Eval_Cmd
/*
* Evaluate a string as Duktape code in the selected heap.
* Usage: eval token code
* Return value: the result of the evaluation coerced to string.
* Side effects: may change the Duktape interpreter heap.
*/
static int
Eval_Cmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
duk_context *ctx;
duk_int_t duk_result;
const char *js_code;
if (objc != 3) {
Tcl_WrongNumArgs(interp, 1, objv, USAGE_EVAL);
return TCL_ERROR;
}
ctx = parse_id(cdata, interp, objv[1], 0);
if (ctx == NULL) {
return TCL_ERROR;
}
js_code = Tcl_GetString(objv[2]);
duk_result = duk_peval_string(ctx, js_code);
Tcl_SetObjResult(interp,
Tcl_NewStringObj(
duk_safe_to_string(ctx, -1), -1));
duk_pop(ctx);
if (duk_result == 0) {
return TCL_OK;
} else {
return TCL_ERROR;
}
}
开发者ID:dbohdan,项目名称:tcl-duktape,代码行数:38,代码来源:tcl-duktape.c
示例10: duk_push_context_dump
DUK_EXTERNAL void duk_push_context_dump(duk_context *ctx) {
duk_idx_t idx;
duk_idx_t top;
/* We don't duk_require_stack() here now, but rely on the caller having
* enough space.
*/
top = duk_get_top(ctx);
duk_push_array(ctx);
for (idx = 0; idx < top; idx++) {
duk_dup(ctx, idx);
duk_put_prop_index(ctx, -2, idx);
}
/* XXX: conversion errors should not propagate outwards.
* Perhaps values need to be coerced individually?
*/
duk_bi_json_stringify_helper(ctx,
duk_get_top_index(ctx), /*idx_value*/
DUK_INVALID_INDEX, /*idx_replacer*/
DUK_INVALID_INDEX, /*idx_space*/
DUK_JSON_FLAG_EXT_CUSTOM |
DUK_JSON_FLAG_ASCII_ONLY |
DUK_JSON_FLAG_AVOID_KEY_QUOTES /*flags*/);
duk_push_sprintf(ctx, "ctx: top=%ld, stack=%s", (long) top, (const char *) duk_safe_to_string(ctx, -1));
duk_replace(ctx, -3); /* [ ... arr jsonx(arr) res ] -> [ ... res jsonx(arr) ] */
duk_pop(ctx);
DUK_ASSERT(duk_is_string(ctx, -1));
}
开发者ID:CarterTsai,项目名称:duktape,代码行数:31,代码来源:duk_api_debug.c
示例11: test_basic
static duk_ret_t test_basic(duk_context *ctx, void *udata) {
duk_idx_t i, n;
duk_int_t rc;
(void) udata;
duk_push_undefined(ctx);
duk_push_null(ctx);
duk_push_true(ctx);
duk_push_false(ctx);
duk_push_string(ctx, "foo");
duk_push_int(ctx, 123);
duk_push_object(ctx);
duk_push_pointer(ctx, (void *) NULL);
duk_push_pointer(ctx, (void *) 0xdeadbeefUL);
n = duk_get_top(ctx);
printf("top: %ld\n", (long) n);
for (i = 0; i <= n; i++) {
rc = duk_safe_call(ctx, safe_helper, (void *) i, 0, 1);
if (rc != DUK_EXEC_SUCCESS) {
printf("index %ld: %s\n", (long) i, duk_safe_to_string(ctx, -1));
}
duk_pop(ctx);
}
printf("final top: %ld\n", (long) duk_get_top(ctx));
return 0;
}
开发者ID:fatcerberus,项目名称:duktape,代码行数:29,代码来源:test-opt-pointer.c
示例12: test_basic
/* Basic dump/load test which exercises all constant types and has an inner
* function. Hex dumping the bytecode provides an exact test case dependency
* to the dump format so that any accidental changes break the test.
*/
static duk_ret_t test_basic(duk_context *ctx) {
unsigned char *p;
duk_size_t i, sz;
/* Integer constants generate LDINT now so also use a fractional
* constant to exercise number constants.
*
* Compiled as a program; force source filename.
*/
duk_push_string(ctx, "print('hello', (function adder(x,y) { return x+y; })(1, 2), 3.14);");
duk_push_string(ctx, "fakeFilename.js");
duk_compile(ctx, 0);
duk_dump_function(ctx);
printf("dump result type: %d\n", (int) duk_get_type(ctx, -1));
fflush(stdout);
p = (unsigned char *) duk_get_buffer(ctx, -1, &sz);
for (i = 0; i < sz; i++) {
printf("%02x", (int) p[i]);
}
printf("\n");
fflush(stdout);
/* Load test function from dump and execute it. */
duk_load_function(ctx);
printf("load result type: %d\n", (int) duk_get_type(ctx, -1));
fflush(stdout);
duk_call(ctx, 0);
printf("call result type: %d\n", (int) duk_get_type(ctx, -1));
fflush(stdout);
printf("call result: %s\n", duk_safe_to_string(ctx, -1));
printf("final top: %ld\n", (long) duk_get_top(ctx));
return 0;
}
开发者ID:nivertech,项目名称:duktape,代码行数:38,代码来源:test-dump-load-basic.c
示例13: duk_push_global_stash
Variant DuktapeScriptFunction::call(const std::vector<Variant> & args)
{
// Get function wrapper from stash
duk_push_global_stash(m_context);
duk_get_prop_index(m_context, -1, m_stashIndex);
// Push arguments
for (Variant var : args)
{
m_scriptBackend->pushToDukStack(var);
}
// Call function
duk_int_t error = duk_pcall(m_context, args.size());
// Check for error
if (error)
{
// Raise script exception
m_scriptBackend->m_scriptContext->scriptException(std::string(duk_safe_to_string(m_context, -1)));
duk_pop_2(m_context);
return Variant();
}
// Convert return value
Variant value = m_scriptBackend->fromDukStack(-1);
duk_pop_2(m_context);
return value;
}
开发者ID:Beta-Alf,项目名称:cppexpose,代码行数:29,代码来源:DuktapeScriptFunction.cpp
示例14: test_internal_prototype_lost
/* Custom internal prototype is lost during a dump/load. */
static duk_ret_t test_internal_prototype_lost(duk_context *ctx) {
duk_eval_string(ctx,
"(function () {\n"
" var f = function test() {};\n"
" Object.setPrototypeOf(f, { myProperty: 'myValue' });\n"
" print(f.myProperty);\n"
" return f;\n"
"})()");
duk_dump_function(ctx);
duk_load_function(ctx);
duk_get_prop_string(ctx, -1, "myProperty");
printf("myProperty: %s\n", duk_safe_to_string(ctx, -1));
duk_pop(ctx);
duk_get_prototype(ctx, -1);
duk_eval_string(ctx, "Function.prototype");
printf("f prototype is Function.prototype: %d\n", (int) duk_strict_equals(ctx, -1, -2));
duk_pop_2(ctx);
duk_pop(ctx);
printf("final top: %ld\n", (long) duk_get_top(ctx));
return 0;
}
开发者ID:nivertech,项目名称:duktape,代码行数:26,代码来源:test-dump-load-basic.c
示例15: duk_push_array
void StyleContext::initFunctions(const Scene& _scene) {
if (_scene.id == m_sceneId) {
return;
}
m_sceneId = _scene.id;
auto arr_idx = duk_push_array(m_ctx);
int id = 0;
for (auto& function : _scene.functions()) {
//logMsg("compile '%s'\n", function.c_str());
duk_push_string(m_ctx, function.c_str());
duk_push_string(m_ctx, "");
if (duk_pcompile(m_ctx, DUK_COMPILE_FUNCTION) == 0) {
duk_put_prop_index(m_ctx, arr_idx, id);
} else {
logMsg("Error: compile failed: %s\n", duk_safe_to_string(m_ctx, -1));
duk_pop(m_ctx);
}
id++;
}
if (!duk_put_global_string(m_ctx, FUNC_ID)) {
logMsg("Error: 'fns' object not set\n");
}
DUMP("setScene - %d functions\n", id);
}
开发者ID:xvilan,项目名称:tangram-es,代码行数:30,代码来源:styleContext.cpp
示例16: es_sqlite_create
static int
es_sqlite_create(duk_context *ctx)
{
char path[PATH_MAX];
char errbuf[512];
es_context_t *ec = es_get(ctx);
const char *name = duk_safe_to_string(ctx, 0);
// Create the db-dir for this plugin
snprintf(path, sizeof(path), "%s/databases", ec->ec_storage);
if(fa_makedirs(path, errbuf, sizeof(errbuf)))
duk_error(ctx, DUK_ERR_ERROR, "Unable to create directory %s -- %s",
path, errbuf);
snprintf(path, sizeof(path), "%s/databases/%s", ec->ec_storage, name);
sqlite3 *db = db_open(path, 0);
if(db == NULL)
duk_error(ctx, DUK_ERR_ERROR, "Unable to open database -- check logs");
es_sqlite_t *es = es_resource_create(ec, &es_resource_sqlite, 0);
es->es_db = db;
es->es_name = strdup(name);
es_resource_push(ctx, &es->super);
return 1;
}
开发者ID:bguerreiro,项目名称:movian,代码行数:31,代码来源:es_sqlite.c
示例17: test_ecma_call_success
static duk_ret_t test_ecma_call_success(duk_context *ctx) {
duk_idx_t i;
/* Ensure stack space for a lot of elements. */
duk_require_stack(ctx, STACK_REQUIRE + 1);
/* Make a function call. Call handling resizes the value stack
* back and forth. At the end, the value stack guaranteed size
* must include the STACK_REQUIRE checked above.
*/
duk_eval_string(ctx, "(function () { print('hello from ecma func'); return 123 })");
duk_call(ctx, 0 /*nargs*/);
printf("duk_call: %s\n", duk_safe_to_string(ctx, -1));
/* It would be quite awkward for user code to have no stack
* guarantees at this point, i.e. require the user code to
* call duk_require_stack(ctx, STACK_REQUIRE) again here.
*/
for (i = 0; i < STACK_REQUIRE; i++) {
duk_push_int(ctx, 123);
}
printf("final top: %ld\n", (long) duk_get_top(ctx));
return 0;
}
开发者ID:black13,项目名称:duktape_games,代码行数:27,代码来源:test-dev-valstack-checked-size-call.cpp
示例18: test_2a
static duk_ret_t test_2a(duk_context *ctx, void *udata) {
(void) udata;
/* Test first with nothing on stack index -3. */
duk_safe_call(ctx, test__null, NULL, 0, 1); printf("%s\n", duk_safe_to_string(ctx, 0));
duk_pop(ctx);
duk_set_top(ctx, 0); duk_push_undefined(ctx); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_null(ctx); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_true(ctx); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_false(ctx); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_number(ctx, 123.0); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_string(ctx, "foo\x00" "bar"); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_fixed_buffer(ctx, 16); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_pointer(ctx, NULL); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_pointer(ctx, (void *) 0xdeadbeefUL); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_object(ctx); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_array(ctx); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_c_function(ctx, dummy_func, 0); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_c_lightfunc(ctx, dummy_func, 0, 0, 0); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_eval_string(ctx, "(function dummy(){})"); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_thread(ctx); test__require_calls(ctx);
printf("done\n");
return 0;
}
开发者ID:fatcerberus,项目名称:duktape,代码行数:26,代码来源:test-dev-api-verbose-error-messages-gh441.c
示例19: test_mandel
/* Dump/load mandelbrot. No inner functions but a bit more code. */
static duk_ret_t test_mandel(duk_context *ctx) {
unsigned char *p;
duk_size_t i, sz;
printf("Mandelbrot source length: %ld\n", (long) strlen(MANDELBROT));
/* Compiled as a function; force source filename. */
duk_push_string(ctx, MANDELBROT);
duk_push_string(ctx, "mandel.js");
duk_compile(ctx, DUK_COMPILE_FUNCTION);
duk_dump_function(ctx);
p = (unsigned char *) duk_get_buffer(ctx, -1, &sz);
for (i = 0; i < sz; i++) {
printf("%02x", (int) p[i]);
}
printf("\n");
fflush(stdout);
/* Load test function from dump and execute it. */
duk_load_function(ctx);
duk_call(ctx, 0);
printf("call result: %s\n", duk_safe_to_string(ctx, -1));
printf("final top: %ld\n", (long) duk_get_top(ctx));
return 0;
}
开发者ID:nivertech,项目名称:duktape,代码行数:28,代码来源:test-dump-load-basic.c
示例20: kbjs_sleep
/*----------------------------------------------------------------------------*/
static duk_ret_t
kbjs_sleep(duk_context *context)
{
/* Check if first argument is a number */
/* STACK: [..., interval] */
if (duk_is_nan(context, (duk_idx_t)-1))
duk_error(context,
(duk_errcode_t)kbjs_ArgumentTypeError,
kbjs_Error_fmt(kbjs_ArgumentTypeError),
SLEEP_FUNC_NAME,
"Number",
0,
duk_safe_to_string(context, (duk_idx_t)-1));
/* Get first argument as integer in miliseconds */
long ms = (long)floor(fabs(duk_get_number(context, (duk_idx_t)-1)));
long s = ms / S_TO_MS;
/* Sleep this thread */
struct timespec interval =
{
(time_t)s,
(ms - s*S_TO_MS)*MS_TO_NS
};
nanosleep(&interval, NULL);
return (duk_ret_t)0;
}
开发者ID:petervaro,项目名称:hackathon,代码行数:30,代码来源:built_ins.c
注:本文中的duk_safe_to_string函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论