conversions.yaml 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. definitions:
  2. # the names of the functions - we use this to generate the code and to register the functions in
  3. # the javascript class
  4. ifunction: "js_${generator.prefix}_${class_name}_${func_name}"
  5. sfunction: "js_${generator.prefix}_${class_name}_${func_name}"
  6. constructor: "js_${generator.prefix}_${class_name}_constructor"
  7. conversions:
  8. # some times you want to use a special native type when converting from spidermonkey to native
  9. # the most common case would be from JS-boolean to bool. Using "bool" will fail here since we
  10. # pass the address to the conversion method, and a JSBool is defined as an integer in spidermonkey
  11. native_types:
  12. # JSBool was removed from Firefox v27
  13. # bool: "JSBool"
  14. float: "double"
  15. short: "int32_t"
  16. "unsigned char": "uint16_t"
  17. "char": "int32_t"
  18. "@std::vector<std::basic_string.*>.>.>": "std::vector<std::string>"
  19. "@std::vector<int.*>.>": "std::vector<int>"
  20. "@cocos2d::Map<std::basic_string.*,": "cocos2d::Map<std::string,"
  21. "@std::map<std::basic_string<char>,.*std::basic_string<char>.*>": "std::map<std::string, std::string>"
  22. "@std::map<std::basic_string<char>,.*std::basic_string<char>.*>*": "std::map<std::string, std::string>*"
  23. ns_map:
  24. "cocos2d::extension::": "cc."
  25. "cocos2d::ui::": "ccui."
  26. "cocos2d::": "cc."
  27. "spine::": "sp."
  28. "cocostudio::": "ccs."
  29. "cocosbuilder::": "cc."
  30. "CocosDenshion::": "cc."
  31. to_native:
  32. # jsval to int
  33. int: "ok &= jsval_to_int32(cx, ${in_value}, (int32_t *)&${out_value})"
  34. "unsigned int": "ok &= jsval_to_uint32(cx, ${in_value}, &${out_value})"
  35. "unsigned char": "ok &= jsval_to_uint16(cx, ${in_value}, &${out_value})"
  36. short: "ok &= jsval_to_int32(cx, ${in_value}, &${out_value})"
  37. "unsigned short": "ok &= jsval_to_ushort(cx, ${in_value}, &${out_value})"
  38. char: "ok &= jsval_to_int32(cx, ${in_value}, &${out_value})"
  39. bool: "${out_value} = JS::ToBoolean(JS::RootedValue(cx, ${in_value}))"
  40. float: "ok &= JS::ToNumber( cx, JS::RootedValue(cx, ${in_value}), &${out_value})"
  41. double: "ok &= JS::ToNumber( cx, JS::RootedValue(cx, ${in_value}), &${out_value})"
  42. long: "ok &= pluginx::jsval_to_long(cx, ${in_value}, &${out_value})"
  43. "unsigned long": "ok &= jsval_to_ulong(cx, ${in_value}, &${out_value})"
  44. "ssize_t": "ok &= jsval_to_ssize(cx, ${in_value}, &${out_value})"
  45. # jsval has to be a TypedArray, a UInt32Array with 2 elements
  46. "long long": "ok &= jsval_to_long_long(cx, ${in_value}, &${out_value})"
  47. "std::string": "ok &= jsval_to_std_string(cx, ${in_value}, &${out_value})"
  48. "char*": "std::string ${out_value}_tmp; ok &= jsval_to_std_string(cx, ${in_value}, &${out_value}_tmp); ${out_value} = ${out_value}_tmp.c_str()"
  49. "@map<std::basic_string<char>,.*std::basic_string<char>.*>": "ok &= jsval_to_std_map_string_string(cx, ${in_value}, &${out_value})"
  50. "@map<std::basic_string<char>,.*std::basic_string<char>.*>\\*": "std::map<std::string, std::string> ${out_value}_tmp; ok &= jsval_to_std_map_string_string(cx, ${in_value}, &${out_value}_tmp); ${out_value} = &${out_value}_tmp"
  51. "Point": "ok &= jsval_to_ccpoint(cx, ${in_value}, &${out_value})"
  52. "Rect": "ok &= jsval_to_ccrect(cx, ${in_value}, &${out_value})"
  53. "Size": "ok &= jsval_to_ccsize(cx, ${in_value}, &${out_value})"
  54. "Color4B": "ok &= jsval_to_cccolor4b(cx, ${in_value}, &${out_value})"
  55. "Color4F": "ok &= jsval_to_cccolor4f(cx, ${in_value}, &${out_value})"
  56. "Color3B": "ok &= jsval_to_cccolor3b(cx, ${in_value}, &${out_value})"
  57. "Array*": "ok &= jsval_to_ccarray(cx, ${in_value}, &${out_value})"
  58. "Dictionary*": "ok &= jsval_to_ccdictionary(cx, ${in_value}, &${out_value})"
  59. "AffineTransform": "ok &= jsval_to_ccaffinetransform(cx, ${in_value}, &${out_value})"
  60. "FontDefinition": "ok &= jsval_to_FontDefinition(cx, ${in_value}, &${out_value})"
  61. "String*": "std::string ${out_value}_tmp; ok &= jsval_to_std_string(cx, ${in_value}, &${out_value}_tmp); ${out_value} = cocos2d::String::create(${out_value}_tmp)"
  62. "@Vector<.*>": "ok &= jsval_to_ccvector(cx, ${in_value}, &${out_value})"
  63. "@Map<std::basic_string.*>": "ok &= jsval_to_ccmap_string_key(cx, ${in_value}, &${out_value})"
  64. "Value": "ok &= jsval_to_ccvalue(cx, ${in_value}, &${out_value})"
  65. "ValueMap": "ok &= jsval_to_ccvaluemap(cx, ${in_value}, &${out_value})"
  66. "ValueMapIntKey": "ok &= jsval_to_ccvaluemapintkey(cx, ${in_value}, &${out_value})"
  67. "ValueVector": "ok &= jsval_to_ccvaluevector(cx, ${in_value}, &${out_value})"
  68. "@vector<std::basic_string.*>": "ok &= jsval_to_std_vector_string(cx, ${in_value}, &${out_value})"
  69. "@vector<int.*>": "ok &= jsval_to_std_vector_int(cx, ${in_value}, &${out_value})"
  70. "Acceleration": "ok &= jsval_to_ccacceleration(cx, ${in_value}, &${out_value})"
  71. "Mat4": "ok &= jsval_to_matrix(cx, ${in_value}, &${out_value})"
  72. "Vec2": "ok &= jsval_to_vector2(cx, ${in_value}, &${out_value})"
  73. "Vec3": "ok &= jsval_to_vector3(cx, ${in_value}, &${out_value})"
  74. "BlendFunc": "ok &= jsval_to_blendfunc(cx, ${in_value}, &${out_value})"
  75. object: |
  76. do {
  77. ${($level + 1) * ' '}if (!${in_value}.isObject()) { ok = false; break; }
  78. ${($level + 1) * ' '}js_proxy_t *jsProxy;
  79. ${($level + 1) * ' '}JSObject *tmpObj = JSVAL_TO_OBJECT(${in_value});
  80. ${($level + 1) * ' '}jsProxy = jsb_get_js_proxy(tmpObj);
  81. ${($level + 1) * ' '}${out_value} = (${ntype})(jsProxy ? jsProxy->ptr : NULL);
  82. ${($level + 1) * ' '}JSB_PRECONDITION2( ${out_value}, cx, false, "Invalid Native Object");
  83. ${($level + 0) * ' '}} while (0)
  84. from_native:
  85. # int to jsval
  86. int: "${out_value} = int32_to_jsval(cx, ${in_value})"
  87. "unsigned int": "${out_value} = uint32_to_jsval(cx, ${in_value})"
  88. "unsigned short": "${out_value} = ushort_to_jsval(cx, ${in_value})"
  89. "unsigned char": "${out_value} = uint32_to_jsval(cx, ${in_value})"
  90. "long long": "${out_value} = long_long_to_jsval(cx, ${in_value})"
  91. "std::string": "${out_value} = std_string_to_jsval(cx, ${in_value})"
  92. "basic_string<char>": "${out_value} = std_string_to_jsval(cx, ${in_value})"
  93. "char*": "${out_value} = c_string_to_jsval(cx, ${in_value})"
  94. bool: "${out_value} = BOOLEAN_TO_JSVAL(${in_value})"
  95. float: "${out_value} = DOUBLE_TO_JSVAL(${in_value})"
  96. double: "${out_value} = DOUBLE_TO_JSVAL(${in_value})"
  97. long: "${out_value} = long_to_jsval(cx, ${in_value})"
  98. "unsigned long": "${out_value} = ulong_to_jsval(cx, ${in_value})"
  99. "ssize_t": "${out_value} = ssize_to_jsval(cx, ${in_value})"
  100. "Point": "${out_value} = ccpoint_to_jsval(cx, ${in_value})"
  101. "Rect": "${out_value} = ccrect_to_jsval(cx, ${in_value})"
  102. "Size": "${out_value} = ccsize_to_jsval(cx, ${in_value})"
  103. "Color4B": "${out_value} = cccolor4b_to_jsval(cx, ${in_value})"
  104. "Color4F": "${out_value} = cccolor4f_to_jsval(cx, ${in_value})"
  105. "Color3B": "${out_value} = cccolor3b_to_jsval(cx, ${in_value})"
  106. "Array*": "${out_value} = ccarray_to_jsval(cx, ${in_value})"
  107. "Dictionary*": "${out_value} = ccdictionary_to_jsval(cx, ${in_value})"
  108. "AffineTransform": "${out_value} = ccaffinetransform_to_jsval(cx, ${in_value})"
  109. "FontDefinition": "${out_value} = FontDefinition_to_jsval(cx, ${in_value})"
  110. "String*": "${out_value} = std_string_to_jsval(cx, ${in_value}->getCString())"
  111. "@Vector<.*>": "${out_value} = ccvector_to_jsval(cx, ${in_value})"
  112. "@Map<std::basic_string.*>": "${out_value} = ccmap_string_key_to_jsval(cx, ${in_value})"
  113. "Value": "${out_value} = ccvalue_to_jsval(cx, ${in_value})"
  114. "ValueMap": "${out_value} = ccvaluemap_to_jsval(cx, ${in_value})"
  115. "ValueMapIntKey": "${out_value} = ccvaluemapintkey_to_jsval(cx, ${in_value})"
  116. "ValueVector": "${out_value} = ccvaluevector_to_jsval(cx, ${in_value})"
  117. "@vector<std::basic_string.*>": "${out_value} = std_vector_string_to_jsval(cx, ${in_value})"
  118. "@vector<int.*>": "${out_value} = std_vector_int_to_jsval(cx, ${in_value})"
  119. "Acceleration*": "${out_value} = ccacceleration_to_jsval(cx, *${in_value})"
  120. "Mat4": "${out_value} = matrix_to_jsval(cx, ${in_value})"
  121. "Vec2": "${out_value} = vector2_to_jsval(cx, ${in_value})"
  122. "Vec3": "${out_value} = vector3_to_jsval(cx, ${in_value})"
  123. "BlendFunc": "${out_value} = blendfunc_to_jsval(cx, ${in_value})"
  124. object: |
  125. do {
  126. ${($level + 1) * ' '}if (${in_value}) {
  127. ${($level + 2) * ' '}js_proxy_t *jsProxy = js_get_or_create_proxy<${ntype.replace("*", "").replace("const ", "")}>(cx, (${ntype.replace("const ", "")})${in_value});
  128. ${($level + 2) * ' '}${out_value} = OBJECT_TO_JSVAL(jsProxy->obj);
  129. ${($level + 1) * ' '}} else {
  130. ${($level + 2) * ' '}${out_value} = JSVAL_NULL;
  131. ${($level + 1) * ' '}}
  132. ${($level) * ' '}} while (0)