本文整理汇总了C++中duk_to_int函数的典型用法代码示例。如果您正苦于以下问题:C++ duk_to_int函数的具体用法?C++ duk_to_int怎么用?C++ duk_to_int使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了duk_to_int函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: i2c_enable_device
/**
* Enable the I2C bus on 2 GPIO pins. Expect two integer
* arguments, this first is the SDA gpio pin number and
* the second is the SCL gpio pin number.
* @param ctx the duktape context.
* @return the name of the created i2c device.
*/
duk_ret_t i2c_enable_device(duk_context *ctx)
{
char* buff[256];
// Expect 2 arguments
int n = duk_get_top(ctx);
if(n != 2) {
return DUK_RET_API_ERROR;
}
// Get the SDA and SDL pin number
int sda_pin = duk_to_int(ctx, 0);
int scl_pin = duk_to_int(ctx, 1);
// Generate the insmod command
sprintf(buff, "insmod i2c-gpio-custom bus0=0,%d,%d > /dev/null", sda_pin, scl_pin);
// Insert the kernel modules
system("insmod i2c-dev > /dev/null");
system(buff);
// Push the name of the i2c device to the stack.
duk_push_string(ctx, "/dev/i2c-0");
return 1;
}
开发者ID:dptechnics,项目名称:DPT-JS,代码行数:32,代码来源:dpt_i2c.c
示例2: duk_btnp
static duk_ret_t duk_btnp(duk_context* duk)
{
tic_machine* machine = getDukMachine(duk);
tic_mem* memory = (tic_mem*)machine;
if (duk_is_null_or_undefined(duk, 0))
{
duk_push_uint(duk, memory->api.btnp(memory, -1, -1, -1));
}
else if(duk_is_null_or_undefined(duk, 1) && duk_is_null_or_undefined(duk, 2))
{
s32 index = duk_to_int(duk, 0) & 0x1f;
duk_push_boolean(duk, memory->api.btnp(memory, index, -1, -1));
}
else
{
s32 index = duk_to_int(duk, 0) & 0x1f;
u32 hold = duk_to_int(duk, 1);
u32 period = duk_to_int(duk, 2);
duk_push_boolean(duk, memory->api.btnp(memory, index, hold, period));
}
return 1;
}
开发者ID:rdrpenguin04,项目名称:TIC-80,代码行数:26,代码来源:jsapi.c
示例3: sys1_poll
static int sys1_poll(duk_context *ctx)
{
int nfds = duk_to_int(ctx, 1);
int timeout = duk_to_int(ctx, 2);
int i, rc;
struct pollfd *fds;
fds = malloc(sizeof(struct pollfd)*nfds);
memset(fds, 0, sizeof(struct pollfd)*nfds);
for(i=0;i<nfds;i++) {
duk_get_prop_index(ctx, 0, i);
duk_get_prop_string(ctx, 3, "fd");
fds[i].fd = duk_to_int(ctx, 4);
duk_get_prop_string(ctx, 3, "events");
fds[i].events = duk_to_int(ctx, 5);
duk_pop_n(ctx, 3);
}
rc = poll(fds, nfds, timeout);
duk_push_object(ctx);
duk_push_int(ctx, rc);
duk_put_prop_string(ctx, -2, "rc");
duk_dup(ctx, 0); // dup reference to arg0 array
for(i=0;i<nfds;i++) {
duk_get_prop_index(ctx, -1, i); // fetch object from array at i
duk_push_int(ctx, fds[i].revents);
duk_put_prop_string(ctx, -2, "revents"); // put revents into object
duk_pop(ctx); // remove object from stack
}
duk_put_prop_string(ctx, -2, "fds");
return 1;
}
开发者ID:jelaas,项目名称:sysjs,代码行数:34,代码来源:sys1.c
示例4: duk_keyp
static s32 duk_keyp(duk_context* duk)
{
tic_machine* machine = getDukMachine(duk);
tic_mem* tic = &machine->memory;
if (duk_is_null_or_undefined(duk, 0))
{
duk_push_boolean(duk, tic->api.keyp(tic, tic_key_unknown, -1, -1));
}
else
{
tic_key key = duk_to_int(duk, 0);
if(key >= tic_key_escape)
{
return duk_error(duk, DUK_ERR_ERROR, "unknown keyboard code\n");
}
else
{
if(duk_is_null_or_undefined(duk, 1) && duk_is_null_or_undefined(duk, 2))
{
duk_push_boolean(duk, tic->api.keyp(tic, key, -1, -1));
}
else
{
u32 hold = duk_to_int(duk, 1);
u32 period = duk_to_int(duk, 2);
duk_push_boolean(duk, tic->api.keyp(tic, key, hold, period));
}
}
}
return 1;
}
开发者ID:rdrpenguin04,项目名称:TIC-80,代码行数:35,代码来源:jsapi.c
示例5: remapCallback
static void remapCallback(void* data, s32 x, s32 y, RemapResult* result)
{
RemapData* remap = (RemapData*)data;
duk_context* duk = remap->duk;
duk_push_heapptr(duk, remap->remap);
duk_push_int(duk, result->index);
duk_push_int(duk, x);
duk_push_int(duk, y);
duk_pcall(duk, 3);
if(duk_is_array(duk, -1))
{
duk_get_prop_index(duk, -1, 0);
result->index = duk_to_int(duk, -1);
duk_pop(duk);
duk_get_prop_index(duk, -1, 1);
result->flip = duk_to_int(duk, -1);
duk_pop(duk);
duk_get_prop_index(duk, -1, 2);
result->rotate = duk_to_int(duk, -1);
duk_pop(duk);
}
else
{
result->index = duk_to_int(duk, -1);
}
duk_pop(duk);
}
开发者ID:rdrpenguin04,项目名称:TIC-80,代码行数:33,代码来源:jsapi.c
示例6: es_file_read
/**
* fd, buffer, offset, length, position
*/
static int
es_file_read(duk_context *ctx)
{
es_fd_t *efd = es_fd_get(ctx, 0);
duk_size_t bufsize;
char *buf = duk_require_buffer_data(ctx, 1, &bufsize);
const int offset = duk_to_int(ctx, 2);
const int len = duk_to_int(ctx, 3);
if(offset + len > bufsize)
duk_error(ctx, DUK_ERR_ERROR, "Buffer too small %zd < %d + %d",
bufsize, offset + len);
if(!duk_is_null(ctx, 4)) {
// Seek
fa_seek(efd->efd_fh, duk_require_number(ctx, 4), SEEK_SET);
}
int r = fa_read(efd->efd_fh, buf + offset, len);
if(r < 0)
duk_error(ctx, DUK_ERR_ERROR, "Read error from '%s'", efd->efd_path);
duk_push_int(ctx, r);
return 1;
}
开发者ID:Ezio-PS,项目名称:movian,代码行数:29,代码来源:es_fs.c
示例7: es_file_write
/**
* fd, buffer, offset, length, position
*/
static int
es_file_write(duk_context *ctx)
{
es_fd_t *efd = es_fd_get(ctx, 0);
duk_size_t bufsize;
char *buf = duk_to_buffer(ctx, 1, &bufsize);
int len;
const int offset = duk_to_int(ctx, 2);
if(duk_is_null(ctx, 3)) {
len = bufsize;
} else {
len = duk_to_int(ctx, 3);
}
// Don't read past buffer end
if(offset + len > bufsize)
len = bufsize - offset;
if(!duk_is_null(ctx, 4)) {
// Seek
fa_seek(efd->efd_fh, duk_require_number(ctx, 4), SEEK_SET);
}
int r = fa_write(efd->efd_fh, buf + offset, len);
if(r < 0)
duk_error(ctx, DUK_ERR_ERROR, "Write error to '%s'", efd->efd_path);
duk_push_int(ctx, r);
return 1;
}
开发者ID:Ezio-PS,项目名称:movian,代码行数:34,代码来源:es_fs.c
示例8: sys1_kill
static int sys1_kill(duk_context *ctx)
{
int pid = duk_to_int(ctx, 0);
int sig = duk_to_int(ctx, 1);
int rc;
rc = kill(pid, sig);
duk_push_int(ctx, rc);
return 1;
}
开发者ID:jelaas,项目名称:sysjs,代码行数:10,代码来源:sys1.c
示例9: ncurses_mvprintw
static int ncurses_mvprintw(duk_context *ctx) {
int y = duk_to_int(ctx, 0);
int x = duk_to_int(ctx, 1);
const char *str = duk_to_string(ctx, 2);
int rc;
rc = mvprintw(y, x, "%s", str);
duk_push_int(ctx, rc);
return 1;
}
开发者ID:BpLife,项目名称:duktape,代码行数:10,代码来源:ncurses.c
示例10: duk_mget
static duk_ret_t duk_mget(duk_context* duk)
{
s32 x = duk_is_null_or_undefined(duk, 0) ? 0 : duk_to_int(duk, 0);
s32 y = duk_is_null_or_undefined(duk, 1) ? 0 : duk_to_int(duk, 1);
tic_mem* memory = (tic_mem*)getDukMachine(duk);
u8 value = memory->api.map_get(memory, &memory->ram.map, x, y);
duk_push_uint(duk, value);
return 1;
}
开发者ID:rdrpenguin04,项目名称:TIC-80,代码行数:11,代码来源:jsapi.c
示例11: sys1_fchmod
static int sys1_fchmod(duk_context *ctx)
{
int fd = duk_to_int(ctx, 0);
mode_t mode = duk_to_int(ctx, 1);
int rc;
rc = fchmod(fd, mode);
duk_push_int(ctx, rc);
return 1;
}
开发者ID:jelaas,项目名称:sysjs,代码行数:11,代码来源:sys1.c
示例12: sys1_lseek
static int sys1_lseek(duk_context *ctx)
{
int fd = duk_to_int(ctx, 0);
off_t offset = duk_to_int(ctx, 1);
int whence = duk_to_int(ctx, 2);
off_t rc;
rc = lseek(fd, offset, whence);
duk_push_int(ctx, rc);
return 1;
}
开发者ID:jelaas,项目名称:sysjs,代码行数:12,代码来源:sys1.c
示例13: sys1_listen
static int sys1_listen(duk_context *ctx)
{
int rc;
int fd = duk_to_int(ctx, 0);
int backlog = duk_to_int(ctx, 1);
rc = listen(fd, backlog);
duk_push_number(ctx, rc);
return 1;
}
开发者ID:jelaas,项目名称:sysjs,代码行数:12,代码来源:sys1.c
示例14: sys1_dup2
static int sys1_dup2(duk_context *ctx)
{
int rc;
int oldfd = duk_to_int(ctx, 0);
int newfd = duk_to_int(ctx, 1);
rc = dup2(oldfd, newfd);
duk_push_number(ctx, rc);
return 1;
}
开发者ID:jelaas,项目名称:sysjs,代码行数:12,代码来源:sys1.c
示例15: duk_rectb
static duk_ret_t duk_rectb(duk_context* duk)
{
s32 x = duk_to_int(duk, 0);
s32 y = duk_to_int(duk, 1);
s32 w = duk_to_int(duk, 2);
s32 h = duk_to_int(duk, 3);
s32 color = duk_to_int(duk, 4);
tic_mem* memory = (tic_mem*)getDukMachine(duk);
memory->api.rect_border(memory, x, y, w, h, color);
return 0;
}
开发者ID:rdrpenguin04,项目名称:TIC-80,代码行数:13,代码来源:jsapi.c
示例16: duk_clip
static duk_ret_t duk_clip(duk_context* duk)
{
s32 x = duk_to_int(duk, 0);
s32 y = duk_to_int(duk, 1);
s32 w = duk_is_null_or_undefined(duk, 2) ? TIC80_WIDTH : duk_to_int(duk, 2);
s32 h = duk_is_null_or_undefined(duk, 3) ? TIC80_HEIGHT : duk_to_int(duk, 3);
tic_mem* memory = (tic_mem*)getDukMachine(duk);
memory->api.clip(memory, x, y, w, h);
return 0;
}
开发者ID:rdrpenguin04,项目名称:TIC-80,代码行数:13,代码来源:jsapi.c
示例17: sys1_socket
static int sys1_socket(duk_context *ctx)
{
int fd;
int domain = duk_to_int(ctx, 0);
int type = duk_to_int(ctx, 1);
int protocol = duk_to_int(ctx, 2);
fd = socket(domain, type, protocol);
duk_push_number(ctx, fd);
return 1;
}
开发者ID:jelaas,项目名称:sysjs,代码行数:13,代码来源:sys1.c
示例18: sys1_write
static int sys1_write(duk_context *ctx)
{
int fd = duk_to_int(ctx, 0);
size_t bufsize;
void *buf = duk_to_buffer(ctx, 1, &bufsize);
int len = duk_to_int(ctx, 2);
ssize_t rc;
rc = write(fd, buf, len);
duk_push_int(ctx, rc);
return 1;
}
开发者ID:jelaas,项目名称:sysjs,代码行数:13,代码来源:sys1.c
示例19: duk_map
static duk_ret_t duk_map(duk_context* duk)
{
s32 x = duk_is_null_or_undefined(duk, 0) ? 0 : duk_to_int(duk, 0);
s32 y = duk_is_null_or_undefined(duk, 1) ? 0 : duk_to_int(duk, 1);
s32 w = duk_is_null_or_undefined(duk, 2) ? TIC_MAP_SCREEN_WIDTH : duk_to_int(duk, 2);
s32 h = duk_is_null_or_undefined(duk, 3) ? TIC_MAP_SCREEN_HEIGHT : duk_to_int(duk, 3);
s32 sx = duk_is_null_or_undefined(duk, 4) ? 0 : duk_to_int(duk, 4);
s32 sy = duk_is_null_or_undefined(duk, 5) ? 0 : duk_to_int(duk, 5);
u8 chromakey = duk_is_null_or_undefined(duk, 6) ? -1 : duk_to_int(duk, 6);
s32 scale = duk_is_null_or_undefined(duk, 7) ? 1 : duk_to_int(duk, 7);
tic_mem* memory = (tic_mem*)getDukMachine(duk);
if (duk_is_null_or_undefined(duk, 8))
memory->api.map(memory, &memory->ram.map, &memory->ram.tiles, x, y, w, h, sx, sy, chromakey, scale);
else
{
void* remap = duk_get_heapptr(duk, 8);
RemapData data = {duk, remap};
memory->api.remap((tic_mem*)getDukMachine(duk), &memory->ram.map, &memory->ram.tiles, x, y, w, h, sx, sy, chromakey, scale, remapCallback, &data);
}
return 0;
}
开发者ID:rdrpenguin04,项目名称:TIC-80,代码行数:26,代码来源:jsapi.c
示例20: duk_line
static duk_ret_t duk_line(duk_context* duk)
{
s32 x0 = duk_to_int(duk, 0);
s32 y0 = duk_to_int(duk, 1);
s32 x1 = duk_to_int(duk, 2);
s32 y1 = duk_to_int(duk, 3);
s32 color = duk_to_int(duk, 4);
tic_mem* memory = (tic_mem*)getDukMachine(duk);
memory->api.line(memory, x0, y0, x1, y1, color);
return 0;
}
开发者ID:rdrpenguin04,项目名称:TIC-80,代码行数:14,代码来源:jsapi.c
注:本文中的duk_to_int函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论