本文整理汇总了C++中NSString::getCString方法的典型用法代码示例。如果您正苦于以下问题:C++ NSString::getCString方法的具体用法?C++ NSString::getCString怎么用?C++ NSString::getCString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NSString
的用法示例。
在下文中一共展示了NSString::getCString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadModuleWithId
JSValueRef EJApp::loadModuleWithId(NSString * moduleId, JSValueRef module, JSValueRef exports)
{
NSString * path = NSStringMake(moduleId->getCString() + string(".js"));
NSString * script = NSString::createWithContentsOfFile(pathForResource(path)->getCString());
if( !script ) {
NSLog("Error: Can't Find Module %s", moduleId->getCString() );
return NULL;
}
NSLog("Loading Module: %s", moduleId->getCString() );
JSStringRef scriptJS = JSStringCreateWithUTF8CString(script->getCString());
JSStringRef pathJS = JSStringCreateWithUTF8CString(path->getCString());
JSStringRef parameterNames[] = {
JSStringCreateWithUTF8CString("module"),
JSStringCreateWithUTF8CString("exports"),
};
JSValueRef exception = NULL;
JSObjectRef func = JSObjectMakeFunction( jsGlobalContext, NULL, 2, parameterNames, scriptJS, pathJS, 0, &exception );
JSStringRelease( scriptJS );
JSStringRelease( pathJS );
JSStringRelease(parameterNames[0]);
JSStringRelease(parameterNames[1]);
if( exception ) {
logException(exception, jsGlobalContext);
return NULL;
}
JSValueRef params[] = { module, exports };
return invokeCallback(func, NULL, 2, params);
}
示例2: ej_getNativeClass
JSValueRef ej_getNativeClass(JSContextRef ctx, JSObjectRef object, JSStringRef propertyNameJS, JSValueRef* exception) {
size_t classNameSize = JSStringGetMaximumUTF8CStringSize(propertyNameJS);
char* className = (char*)malloc(classNameSize);
JSStringGetUTF8CString(propertyNameJS, className, classNameSize);
JSObjectRef obj = NULL;
NSString * fullClassName = new NSString();
NSLOG("ej_getNativeClass : EJBinding%s", className);
fullClassName->initWithFormat("EJBinding%s",className);
EJBindingBase* pClass = (EJBindingBase*)NSClassFromString(fullClassName->getCString());
if( pClass ) {
obj = JSObjectMake( ctx, ej_constructorClass, (void *)pClass );
} else {
NSLOG("%s is NULL ... ", fullClassName->getCString());
}
if (obj)
{
NSLOG("constructor js-obj for %s", className);
}
free(className);
fullClassName->autorelease();
return obj ? obj : ej_global_undefined;
}
示例3: JSValueToNSString
EJ_BIND_FUNCTION(EJBindingHttpRequest, setRequestHeader, ctx, argc, argv) {
if (argc < 2) { return NULL; }
NSString *header = JSValueToNSString(ctx, argv[0]);
NSString *value = JSValueToNSString(ctx, argv[1]);
requestHeaders->setObject(value, header->getCString());
return NULL;
}
示例4: loadScriptAtPath
void EJApp::loadScriptAtPath(NSString * path)
{
NSString * script = NSString::createWithContentsOfFile(pathForResource(path)->getCString());
if( !script ) {
NSLOG("Error: Can't Find Script %s", path->getCString() );
return;
}
NSLOG("Loading Script: %s", path->getCString() );
JSStringRef scriptJS = JSStringCreateWithUTF8CString(script->getCString());
JSStringRef pathJS = JSStringCreateWithUTF8CString(path->getCString());
JSValueRef exception = NULL;
JSEvaluateScript( jsGlobalContext, scriptJS, NULL, pathJS, 0, &exception );
logException(exception, jsGlobalContext);
JSStringRelease( scriptJS );
JSStringRelease( pathJS );
}
示例5:
NSString::NSString(const NSString& str)
:m_sString(str.getCString())
{}
示例6: loadLocalhost
void EJBindingHttpRequest::loadLocalhost() {
state = kEJHttpRequestStateLoading;
// No host? Assume we have a local file
EJBindingEventedBase::triggerEvent(NSStringMake("loadstart"), 0, NULL);
EJBindingEventedBase::triggerEvent(NSStringMake("load"), 0, NULL);
// Check file from cache - /data/data/
NSString *urlPath = EJApp::instance()->pathForResource(url);
unsigned long size = 0;
unsigned char *pData = 0;
NSLOG("Search data: %s", urlPath->getCString());
pData = NSString::createFileData(urlPath->getCString(), "rb", &size);
if (pData) {
// Data was found
NSLOG("Data found in data/data");
requestSource = kEJHttpRequestSourceData;
responseBodySize = size;
responseBody = (char *)pData;
} else {
NSLOG("Checking in bundle");
// Check file from main bundle - /assets/EJECTA_APP_FOLDER/
if (EJApp::instance()->aassetManager == NULL) {
NSLOG("Error loading asset manager");
return;
}
const char *filename = urlPath->getCString(); // "dirname/filename.ext";
// Open file
AAsset *asset = AAssetManager_open(EJApp::instance()->aassetManager, filename, AASSET_MODE_UNKNOWN);
if (NULL == asset) {
NSLOG("Error: Cannot find script %s", filename);
return;
}
long size = AAsset_getLength(asset);
unsigned char *buffer = (unsigned char *)malloc(sizeof(char) * size);
int result = AAsset_read(asset, buffer, size);
if (result < 0) {
NSLOG("Error reading file %s", filename);
AAsset_close(asset);
free(buffer);
return;
}
requestSource = kEJHttpRequestSourceAssets;
responseBodySize = result;
responseBody = (char *)buffer;
AAsset_close(asset);
}
state = kEJHttpRequestStateDone;
// A response Object was never added to the response queue so we do not have
// anything to clean on the network thread, but we must create a fake response
// to hold the response code etc.
// Set a response code and emit events
response = new EJHttpResponse(NULL);
response->setResponseCode(200);
// Emit events
EJBindingEventedBase::triggerEvent(NSStringMake("loadend"), 0, NULL);
EJBindingEventedBase::triggerEvent(NSStringMake("readystatechange"), 0, NULL);
}