当前位置: 首页>>代码示例>>C++>>正文


C++ NSString::getCString方法代码示例

本文整理汇总了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);
}
开发者ID:,项目名称:,代码行数:35,代码来源:

示例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;
}
开发者ID:,项目名称:,代码行数:27,代码来源:

示例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;
}
开发者ID:Alamantus,项目名称:Ejecta-X,代码行数:9,代码来源:EJBindingHttpRequest.cpp

示例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 );

}
开发者ID:,项目名称:,代码行数:23,代码来源:

示例5:

NSString::NSString(const NSString& str)
    :m_sString(str.getCString())
{}
开发者ID:,项目名称:,代码行数:3,代码来源:

示例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);
}
开发者ID:Alamantus,项目名称:Ejecta-X,代码行数:66,代码来源:EJBindingHttpRequest.cpp


注:本文中的NSString::getCString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。