mirror of https://github.com/axmolengine/axmol.git
Removing cocosjs_manual_conversions.h(.cpp). Put all jsval <-> native value conversion codes to js_manual_conversions.h(.cpp).
This commit is contained in:
parent
0151ac60ba
commit
20b350a58b
|
@ -1 +1 @@
|
|||
30ca6c02884f9bc20405b3e657b444c0153bead7
|
||||
a70914e0a87ee8ced4d662bd6038fc955e77f6ca
|
|
@ -9,7 +9,6 @@ LOCAL_MODULE_FILENAME := libcocos2dxjsb
|
|||
LOCAL_SRC_FILES := ScriptingCore.cpp \
|
||||
cocos2d_specifics.cpp \
|
||||
js_manual_conversions.cpp \
|
||||
cocosjs_manual_conversions.cpp \
|
||||
js_bindings_core.cpp \
|
||||
js_bindings_opengl.cpp \
|
||||
jsb_opengl_functions.cpp \
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -17,6 +17,7 @@
|
|||
#include "jsapi.h"
|
||||
#include "jsfriendapi.h"
|
||||
#include "spidermonkey_specifics.h"
|
||||
#include "js_manual_conversions.h"
|
||||
|
||||
void js_log(const char *format, ...);
|
||||
|
||||
|
@ -204,45 +205,6 @@ public:
|
|||
int handleKeypadEvent(void* data);
|
||||
};
|
||||
|
||||
// some utility functions
|
||||
// to native
|
||||
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_uint16( JSContext *cx, jsval vp, uint16_t *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_ccpoint(JSContext *cx, jsval v, Point* ret);
|
||||
JSBool jsval_to_ccrect(JSContext *cx, jsval v, Rect* ret);
|
||||
JSBool jsval_to_ccsize(JSContext *cx, jsval v, Size* ret);
|
||||
JSBool jsval_to_cccolor4b(JSContext *cx, jsval v, Color4B* ret);
|
||||
JSBool jsval_to_cccolor4f(JSContext *cx, jsval v, Color4F* ret);
|
||||
JSBool jsval_to_cccolor3b(JSContext *cx, jsval v, Color3B* ret);
|
||||
JSBool jsval_to_ccarray_of_CCPoint(JSContext* cx, jsval v, Point **points, int *numPoints);
|
||||
JSBool jsval_to_ccarray(JSContext* cx, jsval v, Array** ret);
|
||||
JSBool jsval_to_ccdictionary(JSContext* cx, jsval v, Dictionary** ret);
|
||||
JSBool jsval_to_ccacceleration(JSContext* cx,jsval v, Acceleration* ret);
|
||||
JSBool jsvals_variadic_to_ccarray( JSContext *cx, jsval *vp, int argc, Array** ret);
|
||||
JSBool jsval_to_ccaffinetransform(JSContext* cx, jsval v, AffineTransform* ret);
|
||||
JSBool jsval_to_FontDefinition( JSContext *cx, jsval vp, FontDefinition* ret );
|
||||
|
||||
// from native
|
||||
jsval int32_to_jsval( JSContext *cx, int32_t l);
|
||||
jsval uint32_to_jsval( JSContext *cx, uint32_t number );
|
||||
jsval long_long_to_jsval(JSContext* cx, long long 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 ccpoint_to_jsval(JSContext* cx, const Point& v);
|
||||
jsval ccrect_to_jsval(JSContext* cx, const Rect& v);
|
||||
jsval ccsize_to_jsval(JSContext* cx, const Size& v);
|
||||
jsval cccolor4b_to_jsval(JSContext* cx, const Color4B& v);
|
||||
jsval cccolor4f_to_jsval(JSContext* cx, const Color4F& v);
|
||||
jsval cccolor3b_to_jsval(JSContext* cx, const Color3B& v);
|
||||
jsval ccdictionary_to_jsval(JSContext* cx, Dictionary *dict);
|
||||
jsval ccarray_to_jsval(JSContext* cx, Array *arr);
|
||||
jsval ccacceleration_to_jsval(JSContext* cx, const Acceleration& v);
|
||||
jsval ccaffinetransform_to_jsval(JSContext* cx, const AffineTransform& t);
|
||||
jsval FontDefinition_to_jsval(JSContext* cx, const FontDefinition& t);
|
||||
|
||||
JSObject* NewGlobalObject(JSContext* cx, bool debug = false);
|
||||
|
||||
// just a simple utility to avoid mem leaking when using JSString
|
||||
|
|
|
@ -1 +1 @@
|
|||
6558be4f421be9227dc4fabf1b682d479825bd18
|
||||
2a8f07a22574900290f772ad5a580ef9fc57a9b8
|
|
@ -1 +1 @@
|
|||
1c5eb9cd58c82de77374cdfa5c9ff647cc8b2f02
|
||||
ac3eca550f3b923d03d042ed63edf3b66cc183b7
|
|
@ -27,7 +27,6 @@
|
|||
#define __js_bindings_chipmunk_manual
|
||||
|
||||
#include "js_bindings_config.h"
|
||||
#include "cocosjs_manual_conversions.h"
|
||||
#include "js_manual_conversions.h"
|
||||
#include "ScriptingCore.h"
|
||||
#ifdef JSB_INCLUDE_CHIPMUNK
|
||||
|
|
|
@ -1,134 +0,0 @@
|
|||
#include "jsapi.h"
|
||||
#include "jsfriendapi.h"
|
||||
#include "ScriptingCore.h"
|
||||
#include "js_bindings_config.h"
|
||||
#include "cocosjs_manual_conversions.h"
|
||||
|
||||
#define JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
JSBool jsval_to_CCPoint( JSContext *cx, jsval vp, Point *ret )
|
||||
{
|
||||
#ifdef JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES
|
||||
|
||||
JSObject *jsobj;
|
||||
if( ! JS_ValueToObject( cx, vp, &jsobj ) )
|
||||
return JS_FALSE;
|
||||
|
||||
JSB_PRECONDITION( jsobj, "Not a valid JS object");
|
||||
|
||||
JS::RootedValue valx(cx);
|
||||
JS::RootedValue valy(cx);
|
||||
JSBool ok = JS_TRUE;
|
||||
ok &= JS_GetProperty(cx, jsobj, "x", &valx);
|
||||
ok &= JS_GetProperty(cx, jsobj, "y", &valy);
|
||||
|
||||
if( ! ok )
|
||||
return JS_FALSE;
|
||||
|
||||
double x, y;
|
||||
ok &= JS_ValueToNumber(cx, valx, &x);
|
||||
ok &= JS_ValueToNumber(cx, valy, &y);
|
||||
|
||||
if( ! ok )
|
||||
return JS_FALSE;
|
||||
|
||||
ret->x = x;
|
||||
ret->y = y;
|
||||
|
||||
return JS_TRUE;
|
||||
|
||||
#else // #! JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES
|
||||
|
||||
JSObject *tmp_arg;
|
||||
if( ! JS_ValueToObject( cx, vp, &tmp_arg ) )
|
||||
return JS_FALSE;
|
||||
|
||||
JSB_PRECONDITION( tmp_arg && JS_IsTypedArrayObject( tmp_arg, cx ), "Not a TypedArray object");
|
||||
|
||||
JSB_PRECONDITION( JS_GetTypedArrayByteLength( tmp_arg, cx ) == sizeof(cpVect), "Invalid length");
|
||||
|
||||
*ret = *(Point*)JS_GetArrayBufferViewData( tmp_arg, cx );
|
||||
|
||||
return JS_TRUE;
|
||||
#endif // #! JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES
|
||||
}
|
||||
|
||||
|
||||
JSBool jsval_to_CGPoint( JSContext *cx, jsval vp, cpVect *ret )
|
||||
{
|
||||
#ifdef JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES
|
||||
|
||||
JSObject *jsobj;
|
||||
if( ! JS_ValueToObject( cx, vp, &jsobj ) )
|
||||
return JS_FALSE;
|
||||
|
||||
JSB_PRECONDITION( jsobj, "Not a valid JS object");
|
||||
|
||||
JS::RootedValue valx(cx);
|
||||
JS::RootedValue valy(cx);
|
||||
JSBool ok = JS_TRUE;
|
||||
ok &= JS_GetProperty(cx, jsobj, "x", &valx);
|
||||
ok &= JS_GetProperty(cx, jsobj, "y", &valy);
|
||||
|
||||
if( ! ok )
|
||||
return JS_FALSE;
|
||||
|
||||
double x, y;
|
||||
ok &= JS_ValueToNumber(cx, valx, &x);
|
||||
ok &= JS_ValueToNumber(cx, valy, &y);
|
||||
|
||||
if( ! ok )
|
||||
return JS_FALSE;
|
||||
|
||||
ret->x = x;
|
||||
ret->y = y;
|
||||
|
||||
return JS_TRUE;
|
||||
|
||||
#else // #! JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES
|
||||
|
||||
JSObject *tmp_arg;
|
||||
if( ! JS_ValueToObject( cx, vp, &tmp_arg ) )
|
||||
return JS_FALSE;
|
||||
|
||||
JSB_PRECONDITION( tmp_arg && JS_IsTypedArrayObject( tmp_arg, cx ), "Not a TypedArray object");
|
||||
|
||||
JSB_PRECONDITION( JS_GetTypedArrayByteLength( tmp_arg, cx ) == sizeof(cpVect), "Invalid length");
|
||||
|
||||
*ret = *(cpVect*)JS_GetArrayBufferViewData( tmp_arg, cx );
|
||||
|
||||
return JS_TRUE;
|
||||
#endif // #! JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES
|
||||
}
|
||||
|
||||
|
||||
jsval CGPoint_to_jsval( JSContext *cx, cpVect p)
|
||||
{
|
||||
|
||||
#ifdef JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES
|
||||
|
||||
JSObject *object = JS_NewObject(cx, NULL, NULL, NULL );
|
||||
if (!object)
|
||||
return JSVAL_VOID;
|
||||
|
||||
if (!JS_DefineProperty(cx, object, "x", DOUBLE_TO_JSVAL(p.x), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) ||
|
||||
!JS_DefineProperty(cx, object, "y", DOUBLE_TO_JSVAL(p.y), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) )
|
||||
return JSVAL_VOID;
|
||||
|
||||
return OBJECT_TO_JSVAL(object);
|
||||
|
||||
#else // JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES
|
||||
|
||||
#ifdef __LP64__
|
||||
JSObject *typedArray = JS_NewFloat64Array( cx, 2 );
|
||||
#else
|
||||
JSObject *typedArray = JS_NewFloat32Array( cx, 2 );
|
||||
#endif
|
||||
|
||||
cpVect *buffer = (cpVect*)JS_GetArrayBufferViewData(typedArray, cx );
|
||||
*buffer = p;
|
||||
return OBJECT_TO_JSVAL(typedArray);
|
||||
#endif // ! JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
#ifndef __COCOSJS_MANUAL_CONVERSIONS_H__
|
||||
#define __COCOSJS_MANUAL_CONVERSIONS_H__
|
||||
|
||||
#include "chipmunk.h"
|
||||
#include "cocos2d.h"
|
||||
#include "js_manual_conversions.h"
|
||||
|
||||
//#ifdef __cplusplus
|
||||
//extern "C" {
|
||||
//#endif
|
||||
|
||||
JSBool jsval_to_CGPoint( JSContext *cx, jsval vp, cpVect *out );
|
||||
jsval CGPoint_to_jsval( JSContext *cx, cpVect p );
|
||||
|
||||
|
||||
//#ifdef __cplusplus
|
||||
//}
|
||||
//#endif
|
||||
|
||||
#define cpVect_to_jsval CGPoint_to_jsval
|
||||
#define jsval_to_cpVect jsval_to_CGPoint
|
||||
|
||||
#endif /* __COCOSJS_MANUAL_CONVERSIONS_H__ */
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -7,37 +7,70 @@
|
|||
|
||||
#include "jsapi.h"
|
||||
#include "js_bindings_core.h"
|
||||
|
||||
//#ifdef __cplusplus
|
||||
//extern "C" {
|
||||
//#endif
|
||||
#include "cocos2d.h"
|
||||
|
||||
extern JSBool jsval_to_opaque( JSContext *cx, jsval vp, void **out );
|
||||
extern JSBool jsval_to_int( JSContext *cx, jsval vp, int *out);
|
||||
extern JSBool jsval_to_uint( JSContext *cx, jsval vp, unsigned int *out);
|
||||
extern JSBool jsval_to_long( JSContext *cx, jsval vp, long *out);
|
||||
extern JSBool jsval_to_longlong( JSContext *cx, jsval vp, long long *out);
|
||||
extern 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);
|
||||
extern JSBool jsval_to_c_class( JSContext *cx, jsval vp, void **out_native, struct jsb_c_proxy_s **out_proxy);
|
||||
extern jsval int_to_jsval( JSContext *cx, int number );
|
||||
extern jsval uint_to_jsval( JSContext *cx, unsigned int number );
|
||||
extern jsval long_to_jsval( JSContext *cx, long number );
|
||||
extern jsval longlong_to_jsval( JSContext *cx, long long number );
|
||||
/** converts a jsval (JS string) into a char */
|
||||
extern JSBool jsval_to_charptr( JSContext *cx, jsval vp, const char **out);
|
||||
|
||||
extern 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);
|
||||
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) */
|
||||
extern jsval charptr_to_jsval( JSContext *cx, const char *str);
|
||||
|
||||
extern JSBool JSB_jsval_to_int32( JSContext *cx, jsval vp, int32_t *outval );
|
||||
extern JSBool JSB_jsval_to_uint32( JSContext *cx, jsval vp, uint32_t *outval);
|
||||
extern 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 );
|
||||
extern JSBool JSB_jsval_to_uint16( JSContext *cx, jsval vp, uint16_t *outval );
|
||||
|
||||
//#ifdef __cplusplus
|
||||
//}
|
||||
//#endif
|
||||
// some utility functions
|
||||
// to native
|
||||
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_uint16( JSContext *cx, jsval vp, uint16_t *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_ccpoint(JSContext *cx, jsval v, cocos2d::Point* ret);
|
||||
JSBool jsval_to_ccrect(JSContext *cx, jsval v, cocos2d::Rect* ret);
|
||||
JSBool jsval_to_ccsize(JSContext *cx, jsval v, cocos2d::Size* ret);
|
||||
JSBool jsval_to_cccolor4b(JSContext *cx, jsval v, cocos2d::Color4B* ret);
|
||||
JSBool jsval_to_cccolor4f(JSContext *cx, jsval v, cocos2d::Color4F* ret);
|
||||
JSBool jsval_to_cccolor3b(JSContext *cx, jsval v, cocos2d::Color3B* ret);
|
||||
JSBool jsval_to_ccarray_of_CCPoint(JSContext* cx, jsval v, cocos2d::Point **points, int *numPoints);
|
||||
JSBool jsval_to_ccarray(JSContext* cx, jsval v, cocos2d::Array** ret);
|
||||
JSBool jsval_to_ccdictionary(JSContext* cx, jsval v, cocos2d::Dictionary** ret);
|
||||
JSBool jsval_to_ccacceleration(JSContext* cx,jsval v, cocos2d::Acceleration* ret);
|
||||
JSBool jsvals_variadic_to_ccarray( JSContext *cx, jsval *vp, int argc, cocos2d::Array** ret);
|
||||
JSBool jsval_to_ccaffinetransform(JSContext* cx, jsval v, cocos2d::AffineTransform* ret);
|
||||
JSBool jsval_to_FontDefinition( JSContext *cx, jsval vp, cocos2d::FontDefinition* ret );
|
||||
|
||||
// from native
|
||||
jsval int32_to_jsval( JSContext *cx, int32_t l);
|
||||
jsval uint32_to_jsval( JSContext *cx, uint32_t number );
|
||||
jsval long_long_to_jsval(JSContext* cx, long long 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 ccpoint_to_jsval(JSContext* cx, const cocos2d::Point& v);
|
||||
jsval ccrect_to_jsval(JSContext* cx, const cocos2d::Rect& v);
|
||||
jsval ccsize_to_jsval(JSContext* cx, const cocos2d::Size& v);
|
||||
jsval cccolor4b_to_jsval(JSContext* cx, const cocos2d::Color4B& v);
|
||||
jsval cccolor4f_to_jsval(JSContext* cx, const cocos2d::Color4F& v);
|
||||
jsval cccolor3b_to_jsval(JSContext* cx, const cocos2d::Color3B& v);
|
||||
jsval ccdictionary_to_jsval(JSContext* cx, cocos2d::Dictionary *dict);
|
||||
jsval ccarray_to_jsval(JSContext* cx, cocos2d::Array *arr);
|
||||
jsval ccacceleration_to_jsval(JSContext* cx, const cocos2d::Acceleration& v);
|
||||
jsval ccaffinetransform_to_jsval(JSContext* cx, const cocos2d::AffineTransform& t);
|
||||
jsval FontDefinition_to_jsval(JSContext* cx, const cocos2d::FontDefinition& t);
|
||||
|
||||
JSBool jsval_to_CGPoint( JSContext *cx, jsval vp, cpVect *out );
|
||||
jsval CGPoint_to_jsval( JSContext *cx, cpVect p );
|
||||
|
||||
#define cpVect_to_jsval CGPoint_to_jsval
|
||||
#define jsval_to_cpVect jsval_to_CGPoint
|
||||
|
||||
#endif /* __JS_MANUAL_CONVERSIONS_H__ */
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -31,7 +31,6 @@
|
|||
|
||||
#include "jsb_opengl_manual.h"
|
||||
#include "js_manual_conversions.h"
|
||||
#include "cocosjs_manual_conversions.h"
|
||||
#include "js_bindings_core.h"
|
||||
#include "jsb_opengl_functions.h"
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
<ItemGroup>
|
||||
<ClCompile Include="..\..\..\auto-generated\js-bindings\jsb_cocos2dx_auto.cpp" />
|
||||
<ClCompile Include="..\cocos2d_specifics.cpp" />
|
||||
<ClCompile Include="..\cocosjs_manual_conversions.cpp" />
|
||||
<ClCompile Include="..\jsb_opengl_functions.cpp" />
|
||||
<ClCompile Include="..\jsb_opengl_manual.cpp" />
|
||||
<ClCompile Include="..\jsb_opengl_registration.cpp" />
|
||||
|
@ -25,7 +24,6 @@
|
|||
<ItemGroup>
|
||||
<ClInclude Include="..\..\..\auto-generated\js-bindings\jsb_cocos2dx_auto.hpp" />
|
||||
<ClInclude Include="..\cocos2d_specifics.hpp" />
|
||||
<ClInclude Include="..\cocosjs_manual_conversions.h" />
|
||||
<ClInclude Include="..\jsb_helper.h" />
|
||||
<ClInclude Include="..\jsb_opengl_functions.h" />
|
||||
<ClInclude Include="..\jsb_opengl_manual.h" />
|
||||
|
|
|
@ -17,9 +17,6 @@
|
|||
<ClCompile Include="..\cocos2d_specifics.cpp">
|
||||
<Filter>manual</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\cocosjs_manual_conversions.cpp">
|
||||
<Filter>manual</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\js_bindings_core.cpp">
|
||||
<Filter>manual</Filter>
|
||||
</ClCompile>
|
||||
|
@ -49,9 +46,6 @@
|
|||
<ClInclude Include="..\cocos2d_specifics.hpp">
|
||||
<Filter>manual</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocosjs_manual_conversions.h">
|
||||
<Filter>manual</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\js_bindings_config.h">
|
||||
<Filter>manual</Filter>
|
||||
</ClInclude>
|
||||
|
|
Loading…
Reference in New Issue