`//-------------------------------------------------------------------------------------------------------
// Author:HAO Jing
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
`//------------------------------------------------------------------------------------------------------- // Author:HAO Jing // Licensed under the MIT license. See LICENSE file in the project root for full license information. //-------------------------------------------------------------------------------------------------------
include "ChakraCore.h"
include "ChakraCommon.h"
include
include
include
include
include
define FAIL_CHECK(cmd) \
using namespace std; JsValueRef CHAKRA_CALLBACK JSHello(JsValueRef caller,bool isConstructCall,JsValueRef arguments,unsigned short argumentCount,void callbackState); JsValueRef CHAKRA_CALLBACK JSLogCB(JsValueRef caller,bool isConstructCall,JsValueRef arguments,unsigned short argumentCount,void callbackState);
void setCallback(JsValueRef object,const char propertyName,JsNativeFunction callback,void* callbackState); //int x =1; int main() { JsRuntimeHandle runtime; JsContextRef context; JsValueRef result; unsigned currentSourceContext = 0;
}
JsValueRef CHAKRA_CALLBACK JSLogCB(JsValueRef caller,bool isConstructCall,JsValueRef arguments,unsigned short argumentCount,void callbackState) { cout<<argumentCount<<endl; char* buff = nullptr; JsValueRef strMsg; JsConvertValueToString(arguments[1], &strMsg); size_t length; JsCopyString(strMsg, buff, 0, &length); buff = new char[length+1]; JsCopyString(strMsg, buff, length+1, nullptr); cout<<buff<<endl; return JS_INVALID_REFERENCE; }
JsValueRef CHAKRA_CALLBACK JSHello(JsValueRef caller,bool isConstructCall,JsValueRef arguments,unsigned short argumentCount,void callbackState) { //return JS_INVALID_REFERENCE; //JsValueRef ret = JS_INVALID_REFERENCE; double x,y,z; JsNumberToDouble(arguments[1], &x); JsNumberToDouble(arguments[2], &y); z = x+y; JsValueRef ret; const char* msg = "return"; JsCreateString(msg, strlen(msg), &ret); std::cout<<"this is a native function"<<std::endl; return ret; //return ret; }
void setCallback(JsValueRef object,const char propertyName,JsNativeFunction callback,void* callbackState) {
}
`