#include "scripting/js-bindings/manual/scriptingcore.h" #include <sstream> #include <type_traits>/// Args push helpertemplate<typename _ty> inlinevoid jsx_unpack_arg (std::stringstream& SS, int& Carg, const _ ty& arg) {//template adapter:must be numeric type Static_assert (Std::is_integral<_ty>::value | | std::is_flo Ating_point<_ty>::value, "error, jsx_unpack:unsupported type!"); SS << Arg << ","; ++carg;} Inlinevoid Jsx_unpack_arg (std::stringstream& SS, int&/*carg*/) {//Empty arg}inlinevoid Jsx_unpack_arg (std:: stringstream& SS, int& carg, const char* arg) {//numbers SS << "\" "<< arg <<" \ "" << ","; ++carg;} Inlinevoid Jsx_unpack_arg (std::stringstream& SS, int& carg, const std::string& ARG) {ss << "\" "<& Lt Arg << "\" "<<", "; ++carg;} Template<typename _ty, typename..._args> inlinevoid jsx_unpack_arg (std::stringstream& SS, Int& Carg, const _ty& arg1, const _args&...args) {Jsx_unpack_arg (ss, Carg, arg1); Jsx_unpack_arg (ss, Carg, args ...);} template<typename..._args> inlinevoid jsx_vcall (const char* func, const _args&...args) {Std::stringstream ss Treamargs; Sstreamargs.precision (16); Sstreamargs << func << "("; int carg = 0; Jsx_unpack_arg (Sstreamargs, Carg, args ...); Auto Actrualargs = Sstreamargs.str (); if (Carg! = 0) actrualargs.pop_back (); Pop last ', ' Actrualargs.append (");"); Jsval v1; if (! Scriptingcore::getinstance ()->evalstring (Actrualargs.c_str (), &v1)) {Cocos2d::log ("Jsx_vcall call func:%s F Ailed, please make sure config your Project.json properly! ");}
C + + call JS, variable template implementation, easy to call (Cocos2d-x)