本文整理汇总了C++中JS_ValueToInt32函数的典型用法代码示例。如果您正苦于以下问题:C++ JS_ValueToInt32函数的具体用法?C++ JS_ValueToInt32怎么用?C++ JS_ValueToInt32使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JS_ValueToInt32函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: js_cocos2dx_CCMenuItemAtlasFont_create
JSBool js_cocos2dx_CCMenuItemAtlasFont_create(JSContext *cx, uint32_t argc, jsval *vp)
{
const char *arg0 = NULL;
const char *arg1 = NULL;
do {
if (argc >= 5) {
jsval *argv = JS_ARGV(cx, vp);
do { JSString *tmp = JS_ValueToString(cx, argv[0]); arg0 = JS_EncodeString(cx, tmp); } while (0);
do { JSString *tmp = JS_ValueToString(cx, argv[1]); arg1 = JS_EncodeString(cx, tmp); } while (0);
int arg2; if (!JS_ValueToInt32(cx, argv[2], &arg2)) break;
int arg3; if (!JS_ValueToInt32(cx, argv[3], &arg3)) break;
int arg4; if (!JS_ValueToInt32(cx, argv[4], &arg4)) break;
cocos2d::CCMenuItemAtlasFont* ret = cocos2d::CCMenuItemAtlasFont::create(arg0, arg1, arg2, arg3, arg4);
JS_free(cx, (void*)arg0);
JS_free(cx, (void*)arg1);
JSObject *obj = bind_menu_item<cocos2d::CCMenuItemAtlasFont>(cx, ret, (argc == 7 ? argv[6] : JSVAL_VOID), (argc >= 6 ? argv[5] : JSVAL_VOID));
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
return JS_TRUE;
}
} while(0);
JS_free(cx, (void*)arg0);
JS_free(cx, (void*)arg1);
return JS_FALSE;
}
示例2: js_inkey
static JSBool
js_inkey(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
char key[2];
int32 mode=0;
int32 timeout=0;
sbbs_t* sbbs;
JSString* js_str;
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
if(argc)
JS_ValueToInt32(cx,argv[0],&mode);
if(argc>1)
JS_ValueToInt32(cx,argv[1],&timeout);
key[0]=sbbs->inkey(mode,timeout);
key[1]=0;
if((js_str = JS_NewStringCopyZ(cx, key))==NULL)
return(JS_FALSE);
*rval = STRING_TO_JSVAL(js_str);
return(JS_TRUE);
}
示例3: js_printtail
static JSBool
js_printtail(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
int lines=0;
long mode=0;
uintN i;
sbbs_t* sbbs;
JSString* js_str=NULL;
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
for(i=0;i<argc;i++) {
if(JSVAL_IS_NUMBER(argv[i])) {
if(!lines)
JS_ValueToInt32(cx,argv[i],(int32*)&lines);
else
JS_ValueToInt32(cx,argv[i],(int32*)&mode);
} else if(JSVAL_IS_STRING(argv[i]))
js_str = JS_ValueToString(cx, argv[i]);
}
if(js_str==NULL)
return(JS_FALSE);
if(!lines)
lines=5;
sbbs->printtail(JS_GetStringBytes(js_str),lines,mode);
return(JS_TRUE);
}
示例4: jhtml_textarea_setProperty
/**
* This method is called when setting a Property in HTMLTextArea
*/
static JSBool jhtml_textarea_setProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
HTMLElement *pElem = (HTMLElement *) jhutil_GetPrivate(cx, obj);
HTMLTextArea *pText = (pElem)? (HTMLTextArea *) pElem : 0;
if (!pText)
return JS_TRUE;
switch (JSVAL_TO_INT(id))
{
case HTMLTEXTAREAELEMENT_COLS:
if (JSVAL_IS_INT(*vp))
{
int32 cols;
JS_ValueToInt32(cx, *vp, &cols);
pText->SetCols(cols);
pText->Update(0,0);
return JS_TRUE;
}
break;
case HTMLTEXTAREAELEMENT_ROWS:
if (JSVAL_IS_INT(*vp))
{
int32 rows;
JS_ValueToInt32(cx, *vp, &rows);
pText->SetRows(rows);
pText->Update(0,0);
return JS_TRUE;
}
break;
default:
break;
}//end switch
return JS_TRUE;
}
示例5: fill_rectangle
static JSBool
fill_rectangle(JSContext *context, JSObject *obj,
cairo_rectangle_int_t *rect)
{
jsval val;
if (!gjs_object_get_property_const(context, obj, GJS_STRING_X, &val))
return JS_FALSE;
if (!JS_ValueToInt32(context, val, &rect->x))
return JS_FALSE;
if (!gjs_object_get_property_const(context, obj, GJS_STRING_Y, &val))
return JS_FALSE;
if (!JS_ValueToInt32(context, val, &rect->y))
return JS_FALSE;
if (!gjs_object_get_property_const(context, obj, GJS_STRING_WIDTH, &val))
return JS_FALSE;
if (!JS_ValueToInt32(context, val, &rect->width))
return JS_FALSE;
if (!gjs_object_get_property_const(context, obj, GJS_STRING_HEIGHT, &val))
return JS_FALSE;
if (!JS_ValueToInt32(context, val, &rect->height))
return JS_FALSE;
return JS_TRUE;
}
示例6: Window_redraw
JSBool
Window_redraw (JSContext* cx, JSObject* object, uintN argc, jsval* argv, jsval* rval)
{
if (argc != 2 && argc != 0) {
JS_ReportError(cx, "Not enough parameters.");
return JS_FALSE;
}
WINDOW* win = ((WindowInformation*)JS_GetPrivate(cx, object))->win;
JS_BeginRequest(cx);
JS_EnterLocalRootScope(cx);
switch (argc) {
case 0: {
wrefresh(win);
} break;
case 2: {
jsint beg; JS_ValueToInt32(cx, argv[0], &beg);
jsint num; JS_ValueToInt32(cx, argv[1], &num);
wredrawln(win, beg, num);
} break;
}
JS_LeaveLocalRootScope(cx);
JS_EndRequest(cx);
return JS_TRUE;
}
示例7: js_uploaded_file
static JSBool
js_uploaded_file(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
private_t* p;
int32 files=1;
int32 bytes=0;
jsrefcount rc;
scfg_t* scfg;
scfg=JS_GetRuntimePrivate(JS_GetRuntime(cx));
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL)
return JS_FALSE;
if(argc) {
if(!JS_ValueToInt32(cx, argv[0], &bytes))
return JS_FALSE;
}
if(argc>1) {
if(!JS_ValueToInt32(cx, argv[1], &files))
return JS_FALSE;
}
rc=JS_SUSPENDREQUEST(cx);
js_getuserdat(scfg,p);
JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(user_uploaded(scfg, p->user, files, bytes)));
JS_RESUMEREQUEST(cx, rc);
return JS_TRUE;
}
示例8: js_conio_window
static JSBool
js_conio_window(JSContext *cx, uintN argc, jsval *arglist)
{
jsval *argv=JS_ARGV(cx, arglist);
int32 left=1;
int32 top=1;
int32 right=cio_textinfo.screenwidth;
int32 bottom=cio_textinfo.screenheight;
jsrefcount rc;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if(argc > 4)
return(JS_FALSE);
if(argc > 0) {
if(!JSVAL_IS_NUMBER(argv[0]))
return(JS_FALSE);
if(!JS_ValueToInt32(cx, argv[0], &left))
return(JS_FALSE);
}
if(argc > 1) {
if(!JSVAL_IS_NUMBER(argv[1]))
return(JS_FALSE);
if(!JS_ValueToInt32(cx, argv[1], &top))
return(JS_FALSE);
}
if(argc > 2) {
if(!JSVAL_IS_NUMBER(argv[2]))
return(JS_FALSE);
if(!JS_ValueToInt32(cx, argv[2], &right))
return(JS_FALSE);
}
if(argc > 3) {
if(!JSVAL_IS_NUMBER(argv[3]))
return(JS_FALSE);
if(!JS_ValueToInt32(cx, argv[3], &bottom))
return(JS_FALSE);
}
rc=JS_SUSPENDREQUEST(cx);
window(left, top, right, bottom);
JS_RESUMEREQUEST(cx, rc);
if(cio_textinfo.winleft == left
&& cio_textinfo.winright==right
&& cio_textinfo.wintop==top
&& cio_textinfo.winbottom==bottom) {
JS_SET_RVAL(cx, arglist,JSVAL_TRUE);
}
else {
JS_SET_RVAL(cx, arglist,JSVAL_FALSE);
}
return(JS_TRUE);
}
示例9: xgg_pbar_propop_xn_set
/** set numeric property (xn).
*/
JSBool xgg_pbar_propop_xn_set(JSContext *pcxa, JSObject *pobja, jsval id, jsval *vp)
{
XGGPRIVHDR* phdr = JS_GetPrivate(pcxa, pobja);
XGG_PBAR_PRIV* pv0 = JS_GetPrivate(pcxa, pobja);
XJSEXADGELEM* pelem0 = phdr->pxadgelem;
XJSECTX* pjsectx = (XJSECTX*)JS_GetContextPrivate(pcxa);
XJSE_ASSERT(pelem0 != 0); // basicelement inheritances must have this
xjse_result_t xr1;
xjse_int_t nid = 0;//, nvalue = 0;//, n1;
char* psz0;
JS_ValueToInt32(pcxa, id, &nid);
//JS_ValueToInt32(pcxa, vp[0], &nvalue);
//XJSE_TRACE("xgg_pbar_propop_xn_set. [%d](%d)", nid, nvalue);
switch(nid) {
case PBAR_TID_EMPTYIMAGE:
psz0 = JS_GetStringBytes(JS_ValueToString(pcxa, vp[0]));
xr1 = xgg_xadget_reload_img(pjsectx, &(pv0->ppbempty), psz0, 0, 0);
if(xr1 != XJSE_SUCCESS)
goto failed;
if(pelem0->fcx == 0.0f)
pelem0->fcx = (xjse_float_t)(pv0->ppbempty->nimgwidth);
if(pelem0->fcy == 0.0f)
pelem0->fcy = (xjse_float_t)(pv0->ppbempty->nimgheight);
break;
case PBAR_TID_FULLIMAGE:
psz0 = JS_GetStringBytes(JS_ValueToString(pcxa, vp[0]));
xr1 = xgg_xadget_reload_img(pjsectx, &(pv0->ppbfull), psz0, 0, 0);
if(xr1 != XJSE_SUCCESS)
goto failed;
break;
case PBAR_TID_MAX:
JS_ValueToInt32(pcxa, vp[0], &(pv0->nmax));
break;
case PBAR_TID_MIN:
JS_ValueToInt32(pcxa, vp[0], &(pv0->nmin));
break;
case PBAR_TID_VALUE:
JS_ValueToInt32(pcxa, vp[0], &(pv0->nvalue));
break;
default:
XJSE_TRACE("(E) unknown xn prop [property id: %d]", nid);
}
return JS_TRUE;
failed:
return JS_FALSE;
}
示例10: js_getstr
static JSBool
js_getstr(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
char *p;
long mode=0;
uintN i;
size_t maxlen=0;
sbbs_t* sbbs;
JSString* js_str=NULL;
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
for(i=0;i<argc;i++) {
if(JSVAL_IS_NUMBER(argv[i])) {
if(!maxlen)
JS_ValueToInt32(cx,argv[i],(int32*)&maxlen);
else
JS_ValueToInt32(cx,argv[i],(int32*)&mode);
continue;
}
if(JSVAL_IS_STRING(argv[i])) {
js_str = JS_ValueToString(cx, argv[i]);
if (!js_str)
return(JS_FALSE);
}
}
if(!maxlen) maxlen=128;
if((p=(char *)calloc(1,maxlen+1))==NULL)
return(JS_FALSE);
if(js_str!=NULL)
sprintf(p,"%.*s",(int)maxlen,JS_GetStringBytes(js_str));
sbbs->getstr(p,maxlen,mode);
js_str = JS_NewStringCopyZ(cx, p);
free(p);
if(js_str==NULL)
return(JS_FALSE);
*rval = STRING_TO_JSVAL(js_str);
return(JS_TRUE);
}
示例11: JSUpdateStatus
/**
* The function used as ZOOUpdateStatus from the JavaScript environment
* (ZOO-API).
*
* @param cx the JavaScript context
* @param argc the number of parameters
* @param argv1 the parameter values
* @return true
* @see setHeader,_updateStatus
*/
JSBool
JSUpdateStatus(JSContext *cx, uintN argc, jsval *argv1)
{
jsval *argv = JS_ARGV(cx,argv1);
JS_MaybeGC(cx);
int istatus=0;
char *status=NULL;
maps *conf;
if(argc>2){
#ifdef JS_DEBUG
fprintf(stderr,"Number of arguments used to call the function : %i",argc);
#endif
return JS_FALSE;
}
conf=mapsFromJSObject(cx,argv[0]);
if(JS_ValueToInt32(cx,argv[1],&istatus)==JS_TRUE){
char tmpStatus[4];
sprintf(tmpStatus,"%i",istatus);
tmpStatus[3]=0;
status=strdup(tmpStatus);
}
if(getMapFromMaps(conf,"lenv","status")!=NULL){
if(status!=NULL){
setMapInMaps(conf,"lenv","status",status);
free(status);
}
else
setMapInMaps(conf,"lenv","status","15");
_updateStatus(conf);
}
freeMaps(&conf);
free(conf);
JS_MaybeGC(cx);
return JS_TRUE;
}
示例12: JS_ValueToInt32
template<> bool ScriptInterface::FromJSVal<unsigned long>(JSContext* cx, jsval v, unsigned long& out)
{
int32 tmp;
JSBool ok = JS_ValueToInt32(cx, v, &tmp);
out = (unsigned long)tmp;
return ok == JS_TRUE;
}
示例13: TCP_connect
JSBool
TCP_connect (JSContext* cx, JSObject* object, uintN argc, jsval* argv, jsval* rval)
{
char* host;
int port = -1;
jsdouble timeout = 30;
JS_BeginRequest(cx);
if (argc < 1) {
JS_ReportError(cx, "Not enough parameters.");
JS_EndRequest(cx);
return JS_FALSE;
}
jsval jsConnected;
JS_GetProperty(cx, object, "connected", &jsConnected);
if (jsConnected == JSVAL_TRUE) {
JS_ReportError(cx, "The socket is already connected.");
JS_EndRequest(cx);
return JS_FALSE;
}
switch (argc) {
case 3: JS_ValueToNumber(cx, argv[2], &timeout);
case 2: JS_ValueToInt32(cx, argv[1], &port);
case 1: host = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
}
TCPInformation* data = (TCPInformation*) JS_GetPrivate(cx, object);
PRNetAddr addr;
if (__Sockets_initAddr(&addr, host, port) == PR_FAILURE) {
*rval = JSVAL_FALSE;
JS_EndRequest(cx);
return JS_TRUE;
}
if (PR_Connect(data->socket, &addr, (timeout == -1)
? PR_INTERVAL_NO_TIMEOUT
: PR_MicrosecondsToInterval(timeout*1000000)) == PR_FAILURE)
{
if (PR_GetError() == PR_CONNECT_RESET_ERROR) {
JS_ReportError(cx, "Connection reset by peer.");
}
jsConnected = JSVAL_FALSE;
JS_SetProperty(cx, object, "connected", &jsConnected);
JS_EndRequest(cx);
return JS_FALSE;
}
jsConnected = JSVAL_TRUE;
JS_SetProperty(cx, object, "connected", &jsConnected);
JS_EndRequest(cx);
return JS_TRUE;
}
示例14: to_erl_int
int
to_erl_int(emonk_buf_t* buf, JSContext* cx, jsval val)
{
int32_t rval;
if(!JS_ValueToInt32(cx, val, &rval)) return ERROR;
if((unsigned int) rval < 255)
{
REQUEST(2);
BUFPTR[0] = SMALL_INTEGER;
BUFPTR[1] = (char) rval;
buf->used += 2;
}
else
{
REQUEST(5);
BUFPTR[0] = INTEGER;
rval = htonl(rval);
memcpy(BUFPTR+1, &rval, 4);
buf->used += 5;
}
return OK;
}
示例15: js_handle_ctrlkey
static JSBool
js_handle_ctrlkey(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
char key;
int32 mode=0;
sbbs_t* sbbs;
JSString* js_str;
*rval = JSVAL_FALSE;
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
if(JSVAL_IS_INT(argv[0]))
key=(char)JSVAL_TO_INT(argv[0]);
else {
if((js_str=JS_ValueToString(cx, argv[0]))==NULL)
return(JS_FALSE);
key=*JS_GetStringBytes(js_str);
}
if(argc>1)
JS_ValueToInt32(cx, argv[1], &mode);
*rval = BOOLEAN_TO_JSVAL(sbbs->handle_ctrlkey(key,mode)==0);
return(JS_TRUE);
}