mirror of https://github.com/axmolengine/axmol.git
Merge pull request #4395 from dumganhar/iss3288-bind-unsigned-long
closed #3288: Bindings-generator needs to support 'unsigned long'
This commit is contained in:
commit
2bfb6af1d8
|
@ -93,34 +93,6 @@ JSBool jsval_to_int( JSContext *cx, jsval vp, int *ret )
|
||||||
return jsval_to_int32(cx, vp, (int32_t*)ret);
|
return jsval_to_int32(cx, vp, (int32_t*)ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX: sizeof(long) == 8 in 64 bits on OS X... apparently on Windows it is 32 bits (???)
|
|
||||||
JSBool jsval_to_long( JSContext *cx, jsval vp, long *r )
|
|
||||||
{
|
|
||||||
#ifdef __LP64__
|
|
||||||
// compatibility check
|
|
||||||
assert( sizeof(long)==8);
|
|
||||||
JSString *jsstr = JS_ValueToString(cx, vp);
|
|
||||||
JSB_PRECONDITION2(jsstr, cx, JS_FALSE, "Error converting value to string");
|
|
||||||
|
|
||||||
char *str = JS_EncodeString(cx, jsstr);
|
|
||||||
JSB_PRECONDITION2(str, cx, JS_FALSE, "Error encoding string");
|
|
||||||
|
|
||||||
char *endptr;
|
|
||||||
long ret = strtol(str, &endptr, 10);
|
|
||||||
|
|
||||||
*r = ret;
|
|
||||||
return JS_TRUE;
|
|
||||||
|
|
||||||
#else
|
|
||||||
// compatibility check
|
|
||||||
assert( sizeof(int)==4);
|
|
||||||
long ret = JSVAL_TO_INT(vp);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
*r = ret;
|
|
||||||
return JS_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
jsval opaque_to_jsval( JSContext *cx, void *opaque )
|
jsval opaque_to_jsval( JSContext *cx, void *opaque )
|
||||||
{
|
{
|
||||||
#ifdef __LP64__
|
#ifdef __LP64__
|
||||||
|
@ -191,6 +163,21 @@ jsval long_to_jsval( JSContext *cx, long number )
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jsval ulong_to_jsval( JSContext *cx, unsigned long number )
|
||||||
|
{
|
||||||
|
#ifdef __LP64__
|
||||||
|
assert( sizeof(unsigned long)==8);
|
||||||
|
|
||||||
|
char chr[128];
|
||||||
|
snprintf(chr, sizeof(chr)-1, "%lu", number);
|
||||||
|
JSString *ret_obj = JS_NewStringCopyZ(cx, chr);
|
||||||
|
return STRING_TO_JSVAL(ret_obj);
|
||||||
|
#else
|
||||||
|
CCASSERT( sizeof(int)==4, "Error!");
|
||||||
|
return UINT_TO_JSVAL(number);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
jsval longlong_to_jsval( JSContext *cx, long long number )
|
jsval longlong_to_jsval( JSContext *cx, long long number )
|
||||||
{
|
{
|
||||||
#if JSB_REPRESENT_LONGLONG_AS_STR
|
#if JSB_REPRESENT_LONGLONG_AS_STR
|
||||||
|
@ -367,7 +354,52 @@ JSBool jsval_to_uint16( JSContext *cx, jsval vp, uint16_t *outval )
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSBool jsval_to_long_long(JSContext *cx, jsval vp, long long* r) {
|
// XXX: sizeof(long) == 8 in 64 bits on OS X... apparently on Windows it is 32 bits (???)
|
||||||
|
JSBool jsval_to_long( JSContext *cx, jsval vp, long *r )
|
||||||
|
{
|
||||||
|
#ifdef __LP64__
|
||||||
|
// compatibility check
|
||||||
|
assert( sizeof(long)==8);
|
||||||
|
JSString *jsstr = JS_ValueToString(cx, vp);
|
||||||
|
JSB_PRECONDITION2(jsstr, cx, JS_FALSE, "Error converting value to string");
|
||||||
|
|
||||||
|
char *str = JS_EncodeString(cx, jsstr);
|
||||||
|
JSB_PRECONDITION2(str, cx, JS_FALSE, "Error encoding string");
|
||||||
|
|
||||||
|
char *endptr;
|
||||||
|
long ret = strtol(str, &endptr, 10);
|
||||||
|
|
||||||
|
*r = ret;
|
||||||
|
return JS_TRUE;
|
||||||
|
|
||||||
|
#else
|
||||||
|
// compatibility check
|
||||||
|
assert( sizeof(int)==4);
|
||||||
|
long ret = JSVAL_TO_INT(vp);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
*r = ret;
|
||||||
|
return JS_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
JSBool jsval_to_ulong( JSContext *cx, jsval vp, unsigned long *out)
|
||||||
|
{
|
||||||
|
if (out == nullptr)
|
||||||
|
return JS_FALSE;
|
||||||
|
|
||||||
|
long rval = 0;
|
||||||
|
JSBool ret = JS_FALSE;
|
||||||
|
ret = jsval_to_long(cx, vp, &rval);
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
*out = (unsigned long)rval;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSBool jsval_to_long_long(JSContext *cx, jsval vp, long long* r)
|
||||||
|
{
|
||||||
JSObject *tmp_arg;
|
JSObject *tmp_arg;
|
||||||
JSBool ok = JS_ValueToObject( cx, vp, &tmp_arg );
|
JSBool ok = JS_ValueToObject( cx, vp, &tmp_arg );
|
||||||
JSB_PRECONDITION3( ok, cx, JS_FALSE, "Error converting value to object");
|
JSB_PRECONDITION3( ok, cx, JS_FALSE, "Error converting value to object");
|
||||||
|
|
|
@ -9,29 +9,28 @@
|
||||||
#include "js_bindings_core.h"
|
#include "js_bindings_core.h"
|
||||||
#include "cocos2d.h"
|
#include "cocos2d.h"
|
||||||
|
|
||||||
extern JSBool jsval_to_opaque( JSContext *cx, jsval vp, void **out );
|
JSBool jsval_to_opaque( JSContext *cx, jsval vp, void **out );
|
||||||
extern JSBool jsval_to_int( JSContext *cx, jsval vp, int *out);
|
JSBool jsval_to_int( JSContext *cx, jsval vp, int *out);
|
||||||
extern JSBool jsval_to_uint( JSContext *cx, jsval vp, unsigned int *out);
|
JSBool jsval_to_uint( JSContext *cx, jsval vp, unsigned int *out);
|
||||||
extern JSBool jsval_to_long( JSContext *cx, jsval vp, long *out);
|
JSBool jsval_to_c_class( JSContext *cx, jsval vp, void **out_native, struct jsb_c_proxy_s **out_proxy);
|
||||||
extern JSBool jsval_to_c_class( JSContext *cx, jsval vp, void **out_native, struct jsb_c_proxy_s **out_proxy);
|
|
||||||
/** converts a jsval (JS string) into a char */
|
/** converts a jsval (JS string) into a char */
|
||||||
extern JSBool jsval_to_charptr( JSContext *cx, jsval vp, const char **out);
|
JSBool jsval_to_charptr( JSContext *cx, jsval vp, const char **out);
|
||||||
|
|
||||||
extern jsval opaque_to_jsval( JSContext *cx, void* opaque);
|
jsval opaque_to_jsval( JSContext *cx, void* opaque);
|
||||||
extern jsval c_class_to_jsval( JSContext *cx, void* handle, JSObject* object, JSClass *klass, const char* class_name);
|
jsval c_class_to_jsval( JSContext *cx, void* handle, JSObject* object, JSClass *klass, const char* class_name);
|
||||||
extern jsval long_to_jsval( JSContext *cx, long number );
|
|
||||||
extern jsval longlong_to_jsval( JSContext *cx, long long number );
|
|
||||||
|
|
||||||
/* Converts a char ptr into a jsval (using JS string) */
|
/* Converts a char ptr into a jsval (using JS string) */
|
||||||
extern jsval charptr_to_jsval( JSContext *cx, const char *str);
|
jsval charptr_to_jsval( JSContext *cx, const char *str);
|
||||||
extern JSBool JSB_jsval_typedarray_to_dataptr( JSContext *cx, jsval vp, GLsizei *count, void **data, JSArrayBufferViewType t);
|
JSBool JSB_jsval_typedarray_to_dataptr( JSContext *cx, jsval vp, GLsizei *count, void **data, JSArrayBufferViewType t);
|
||||||
extern JSBool JSB_get_arraybufferview_dataptr( JSContext *cx, jsval vp, GLsizei *count, GLvoid **data );
|
JSBool JSB_get_arraybufferview_dataptr( JSContext *cx, jsval vp, GLsizei *count, GLvoid **data );
|
||||||
|
|
||||||
// some utility functions
|
// some utility functions
|
||||||
// to native
|
// to native
|
||||||
JSBool jsval_to_int32( JSContext *cx, jsval vp, int32_t *ret );
|
JSBool jsval_to_int32( JSContext *cx, jsval vp, int32_t *ret );
|
||||||
JSBool jsval_to_uint32( JSContext *cx, jsval vp, uint32_t *ret );
|
JSBool jsval_to_uint32( JSContext *cx, jsval vp, uint32_t *ret );
|
||||||
JSBool jsval_to_uint16( JSContext *cx, jsval vp, uint16_t *ret );
|
JSBool jsval_to_uint16( JSContext *cx, jsval vp, uint16_t *ret );
|
||||||
|
JSBool jsval_to_long( JSContext *cx, jsval vp, long *out);
|
||||||
|
JSBool jsval_to_ulong( JSContext *cx, jsval vp, unsigned long *out);
|
||||||
JSBool jsval_to_long_long(JSContext *cx, jsval v, long long* ret);
|
JSBool jsval_to_long_long(JSContext *cx, jsval v, long long* ret);
|
||||||
JSBool jsval_to_std_string(JSContext *cx, jsval v, std::string* ret);
|
JSBool jsval_to_std_string(JSContext *cx, jsval v, std::string* ret);
|
||||||
JSBool jsval_to_ccpoint(JSContext *cx, jsval v, cocos2d::Point* ret);
|
JSBool jsval_to_ccpoint(JSContext *cx, jsval v, cocos2d::Point* ret);
|
||||||
|
@ -51,6 +50,8 @@ JSBool jsval_to_FontDefinition( JSContext *cx, jsval vp, cocos2d::FontDefinition
|
||||||
// from native
|
// from native
|
||||||
jsval int32_to_jsval( JSContext *cx, int32_t l);
|
jsval int32_to_jsval( JSContext *cx, int32_t l);
|
||||||
jsval uint32_to_jsval( JSContext *cx, uint32_t number );
|
jsval uint32_to_jsval( JSContext *cx, uint32_t number );
|
||||||
|
jsval long_to_jsval( JSContext *cx, long number );
|
||||||
|
jsval ulong_to_jsval(JSContext* cx, unsigned long v);
|
||||||
jsval long_long_to_jsval(JSContext* cx, long long v);
|
jsval long_long_to_jsval(JSContext* cx, long long v);
|
||||||
jsval std_string_to_jsval(JSContext* cx, const std::string& v);
|
jsval std_string_to_jsval(JSContext* cx, const std::string& v);
|
||||||
jsval c_string_to_jsval(JSContext* cx, const char* v, size_t length = -1);
|
jsval c_string_to_jsval(JSContext* cx, const char* v, size_t length = -1);
|
||||||
|
|
|
@ -307,6 +307,30 @@ bool luaval_to_long(lua_State* L,int lo, long* outValue)
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool luaval_to_ulong(lua_State* L,int lo, unsigned long* outValue)
|
||||||
|
{
|
||||||
|
if (NULL == L || NULL == outValue)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
tolua_Error tolua_err;
|
||||||
|
if (!tolua_isnumber(L,lo,0,&tolua_err))
|
||||||
|
{
|
||||||
|
#if COCOS2D_DEBUG >=1
|
||||||
|
luaval_to_native_err(L,"#ferror:",&tolua_err);
|
||||||
|
#endif
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ok)
|
||||||
|
{
|
||||||
|
*outValue = (unsigned long)tolua_tonumber(L, lo, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
bool luaval_to_size(lua_State* L,int lo,Size* outValue)
|
bool luaval_to_size(lua_State* L,int lo,Size* outValue)
|
||||||
{
|
{
|
||||||
if (NULL == L || NULL == outValue)
|
if (NULL == L || NULL == outValue)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit e6c7016f83c9d02e0b8e784c65043369a1745680
|
Subproject commit 3e215fc4865a75e25db6f45115350ef2d7a256ca
|
Loading…
Reference in New Issue