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


C++ JS_EncodeString函数代码示例

本文整理汇总了C++中JS_EncodeString函数的典型用法代码示例。如果您正苦于以下问题:C++ JS_EncodeString函数的具体用法?C++ JS_EncodeString怎么用?C++ JS_EncodeString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了JS_EncodeString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: AfxGlobal_soundRecStart

static JSBool
AfxGlobal_soundRecStart(JSContext *cx, unsigned argc, JS::Value *vp)
{
    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
	if(2 > args.length())
		return JS_FALSE;

	double volume;

	if(!JS::ToNumber(cx, args[1], &volume))
		return JS_FALSE;

    JSString *str = JS_ValueToString(cx, args[0]);
    if (!str)
        return JS_FALSE;

    char *c_str = JS_EncodeString(cx, str);
	if(!c_str)
		return JS_FALSE;

	std::wstring wPath;

	if(!AnsiStringToWideString(c_str, wPath))
	{
		JS_free(cx, c_str);
		return JS_FALSE;
	}

	JS_free(cx, c_str);

	bool result = g_Filming.GetFilmSound()->Start(wPath.c_str(), 0, (float)volume);

	args.rval().set(BOOLEAN_TO_JSVAL(result));
    return JS_TRUE;
}
开发者ID:YaLTeR,项目名称:advancedfx,代码行数:35,代码来源:scripting.cpp

示例2: round_js_sm_engine_run

bool round_js_sm_engine_run(RoundJavaScriptEngine* engine, const char* source, size_t sourceLen, RoundString* result, RoundError* err)
{
  if (!engine)
    return false;

  if (!engine->rt || !engine->cx)
    return false;

  gCurrentJsEngine = engine;

  jsval rval;
  JSBool ok = JS_EvaluateScript(engine->cx, engine->obj, source, (uintN)sourceLen, "", 0, &rval);
  gCurrentJsEngine = NULL;

  if (ok) {
    JSString* rstr = JS_ValueToString(engine->cx, rval);
    if (rstr) {
      if (result) {
        round_string_setvalue(result, JS_EncodeString(engine->cx, rstr));
      }
    }
  }

  return ok;
}
开发者ID:cybergarage,项目名称:round,代码行数:25,代码来源:js_sm_engine.c

示例3: SoundCtor

    // TODO: Add streaming support.
    bool SoundCtor(JSContext *ctx, unsigned argc, JS::Value *vp){
        
        JS::CallArgs args = CallArgsFromVp(argc, vp);
        if(!Turbo::CheckForSingleArg(ctx, args, Turbo::String, __func__))
            return false;
                
        struct Turbo::JSStringHolder<> file(ctx, JS_EncodeString(ctx, args[0].toString()));
        
        const std::string full_path = std::string(TS_GetContextEnvironment(ctx)->directories->sound) + file.string;

        if(!t5::IsFile(full_path)){
            Turbo::SetError(ctx, std::string(BRACKNAME " SoundCtor Error no such file ") + file.string);
            return false;
        }
        
        SF_INFO info;
        SNDFILE *sound_file = sf_open(full_path.c_str(), SFM_READ, &info);
        //sf_command(sound_file, SFC_SET_SCALE_FLOAT_INT_READ, nullptr, SF_TRUE);
        
        if(!sound_file){
            Turbo::SetError(ctx, std::string(BRACKNAME " SoundCtor Error could not open file ") + file.string);
            return false;
        }
        
		int iters = 0;
		Sound *sound = nullptr;
		
		if(player.supportsFloat32()){
			float buffer[0x8000];
			sound = new Sound(player.load((float *)nullptr, 0, info.channels, info.samplerate, info.frames));
			
			while(unsigned long this_read = sf_read_float(sound_file, buffer, 0x10000)){
				player.addToSound(sound, buffer, SamplesToBytes(this_read));
				iters++;
			}
		}
		else if(player.supportsInt16()){
			short buffer[0x10000];
			sound  = new Sound(player.load((short *)nullptr, 0, info.channels, info.samplerate, info.frames));
			
			while(unsigned long this_read = sf_read_short(sound_file, buffer, 0x10000)){
				player.addToSound(sound, buffer, SamplesToBytes(this_read));
				iters++;
			}
        }
		else{
			puts(BRACKNAME " Error bad player on this platform");
		}
		
        printf(BRACKNAME " SoundCtor Info loaded file %s in %i iterations\n", file.string, iters);
        
        sf_close(sound_file);
        
        args.rval().set(OBJECT_TO_JSVAL(sound_proto.wrap(ctx, sound)));
        
        return true;
    }
开发者ID:FlyingJester,项目名称:TurboSphere,代码行数:58,代码来源:script.cpp

示例4: JSGET_PTRSHELL

JSBool S_CCUserDefault::jssetStringForKey(JSContext *cx, uint32_t argc, jsval *vp) {
    JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp);
    S_CCUserDefault* self = NULL; JSGET_PTRSHELL(S_CCUserDefault, self, obj);
    if (self == NULL) return JS_FALSE;
    if (argc == 2) {
        JSString *arg0;
        JSString *arg1;
        JS_ConvertArguments(cx, 2, JS_ARGV(cx, vp), "SS", &arg0, &arg1);
        char *narg0 = JS_EncodeString(cx, arg0);
        std::string narg1(JS_EncodeString(cx, arg1));
        self->setStringForKey(narg0, narg1);
        
        JS_SET_RVAL(cx, vp, JSVAL_TRUE);
        return JS_TRUE;
    }
    JS_SET_RVAL(cx, vp, JSVAL_TRUE);
    return JS_TRUE;
}
开发者ID:136446529,项目名称:book-code,代码行数:18,代码来源:cocos2d_manual_bindings.cpp

示例5: go_setter_callback

/* The property setter callback */
JSBool go_setter_callback(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp) {
	char* cname = JS_EncodeString(cx, JSID_TO_STRING(id));

	JSBool result = call_go_setter(JS_GetPrivate(cx, obj), cname, vp);

	JS_free(cx, (void*)cname);

	return result;
}
开发者ID:MrXiaoZ,项目名称:monkey,代码行数:10,代码来源:monkey.c

示例6: JSGET_PTRSHELL

JSBool S_SimpleNativeClass::jsdoSomeProcessing(JSContext *cx, uint32_t argc, jsval *vp) {
	JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp);
	S_SimpleNativeClass* self = NULL; JSGET_PTRSHELL(S_SimpleNativeClass, self, obj);
	if (self == NULL) return JS_FALSE;
	if (argc == 2) {
		jsval *argv = JS_ARGV(cx, vp);
		JSString *arg0 = JSVAL_TO_STRING(argv[0]);
		std::string narg0 = JS_EncodeString(cx, arg0);
		JSString *arg1 = JSVAL_TO_STRING(argv[1]);
		std::string narg1 = JS_EncodeString(cx, arg1);
		int ret = self->doSomeProcessing(narg0, narg1);
		do { jsval tmp; JS_NewNumberValue(cx, ret, &tmp); JS_SET_RVAL(cx, vp, tmp); } while (0);
		
		return JS_TRUE;
	}
	JS_SET_RVAL(cx, vp, JSVAL_TRUE);
	return JS_TRUE;
}
开发者ID:funkaster,项目名称:testjs,代码行数:18,代码来源:simple_native_generated.cpp

示例7: search_module_in_paths

static gboolean
search_module_in_paths (JSContext    *cx,
                        JSObject     *paths,
                        const gchar  *module_name,
                        gchar       **script,
                        gsize        *script_len,
                        gchar       **file_name,
                        gchar       **search_path,
                        GError      **error)
{
  guint len;
  guint i;
  const gchar *path;

  JSAutoCompartment ac(cx, paths);
  JS_GetArrayLength (cx, paths, &len);

  for (i = 0; i < len; i++)
    {
      JSString *st;
      jsval val;

      JS_GetElement (cx, paths, i, &val);
      st = JS_ValueToString (cx, val);
      path = JS_EncodeString (cx, st);

      *file_name = g_strdup_printf ("%s/%s", path, module_name);

      if (g_file_get_contents (*file_name,
                               script,
                               script_len,
                               error))
        {
          *search_path = g_strdup (path);
          return TRUE;
        }
      else
        {
          if ((*error)->code == G_FILE_ERROR_NOENT ||
              (*error)->code == G_FILE_ERROR_ISDIR)
            {
              g_clear_error (error);
            }
          else
            return FALSE;
        }
    }

  g_set_error (error,
               G_FILE_ERROR,
               G_FILE_ERROR_NOENT,
               "Module '%s' was not found in search paths",
               module_name);

  return FALSE;
}
开发者ID:groleo,项目名称:gjs-commonjs,代码行数:56,代码来源:gjs-require.cpp

示例8: webLaunchBrowser

JSBool webLaunchBrowser(JSContext *cx, uintN argc, jsval *vp) {
	char *name = NULL;
		if(JSVAL_IS_STRING(*JS_ARGV(cx,vp)))
			name = JS_EncodeString(cx,JSVAL_TO_STRING(*JS_ARGV(cx,vp)));
		if(name){
			launchBrowser(name);
			JS_free(cx,name);
		}
	return JS_TRUE;
}
开发者ID:joejoyce,项目名称:jsEngine,代码行数:10,代码来源:web.cpp

示例9: set

 void set(JSString* str, JSContext* cx) {
     this->cx = cx;
     string = str;
     // Not suppored in SpiderMonkey v19
     buffer = JS_EncodeString(cx, string);
     
     // const jschar *chars = JS_GetStringCharsZ(cx, string);
     // size_t l = JS_GetStringLength(string);
     // char* pUTF8Str = cc_utf16_to_utf8((const unsigned short*)chars, l, NULL, NULL);
     // buffer = pUTF8Str;
 }
开发者ID:0309,项目名称:cocos2d-x,代码行数:11,代码来源:jsb_pluginx_basic_conversions.cpp

示例10: DriverManager_getConnection

static JSBool DriverManager_getConnection(JSContext *cx, unsigned argc, jsval *vp)
{
	jsval drivers;
	JS_LookupProperty(cx, JS_THIS_OBJECT(cx, vp), "drivers", &drivers);
	// FIXME check return code; check that drivers is an array
	JSObject *obj = JSVAL_TO_OBJECT(drivers);

	uint32_t len, i;
	JS_GetArrayLength(cx, obj, &len);


	jsval connect_argv[2] = {JS_ARGV(cx, vp)[0]};
	if (argc == 2) {
		/* Caller passed "info" object, so we forward it as-is */
		connect_argv[1] = JS_ARGV(cx, vp)[1];
	} else {
		JSObject *info = JS_NewObject(cx, NULL, NULL, NULL); // FIXME root it to avoid GC
		if (argc > 1)
			JS_DefineProperty(cx, info, "user", JS_ARGV(cx, vp)[1], NULL, NULL, JSPROP_ENUMERATE);
		if (argc > 2)
			JS_DefineProperty(cx, info, "password", JS_ARGV(cx, vp)[2], NULL, NULL, JSPROP_ENUMERATE);

		connect_argv[1] = OBJECT_TO_JSVAL(info);
	};

	jsval reason = JSVAL_NULL;
	for (i = 0; i < len; i++) {
		jsval driver, rval;
		JS_GetElement(cx, obj, i, &driver);

		if (!JS_CallFunctionName(cx, JSVAL_TO_OBJECT(driver), "connect", 2, &connect_argv[0], &rval)) {
			if (JSVAL_IS_NULL(reason))
				JS_GetPendingException(cx, &reason);
			continue;
		}
		if (JSVAL_IS_NULL(rval))
			continue;
		JS_SET_RVAL(cx, vp, rval);
		return JS_TRUE;
	}

	if (JSVAL_IS_NULL(reason)) {
		JSString *url_str = JS_ValueToString(cx, JS_ARGV(cx, vp)[0]);
		// FIXME check return value
		// FIXME root url_str (protect from GC) -> https://developer.mozilla.org/en-US/docs/SpiderMonkey/JSAPI_Reference/JS_ValueToString
		char *url = JS_EncodeString(cx, url_str);
		JS_ReportError(cx, "No suitable driver found for %s", url);
		JS_free(cx, url);
	} else
		JS_SetPendingException(cx, reason);

	JS_SET_RVAL(cx, vp, JSVAL_NULL);
	return JS_FALSE;
}
开发者ID:mindbit,项目名称:libjssql,代码行数:54,代码来源:jssql.c

示例11: JS_ConvertArguments

JSBool S_CCFileUtils::jsgetFileData(JSContext *cx, uint32_t argc, jsval *vp) {
    if (argc == 2) {
        JSString *arg0;
        JSString *arg1;
        unsigned long len;
        JS_ConvertArguments(cx, 2, JS_ARGV(cx, vp), "SS", &arg0, &arg1);
        char *narg0 = JS_EncodeString(cx, arg0);
        char *narg1 = JS_EncodeString(cx, arg1);
        unsigned char *ret = CCFileUtils::sharedFileUtils()->getFileData(narg0, narg1, &len);
        if (ret == NULL) {
            JS_SET_RVAL(cx, vp, JSVAL_NULL);
            return JS_TRUE;
        }
        JSString *str = JS_NewStringCopyN(cx, (const char *)ret, len);
        JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(str));        
        return JS_TRUE;
    }
    JS_SET_RVAL(cx, vp, JSVAL_TRUE);
    return JS_TRUE;
}
开发者ID:136446529,项目名称:book-code,代码行数:20,代码来源:cocos2d_manual_bindings.cpp

示例12: sys_error

static JSBool sys_error(JSContext *cx, unsigned argc, jsval *vp)
{
    JSString *s;
    char *message;
    if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "S", &s))
        return JS_FALSE;
    message = JS_EncodeString(cx, s);
    trap_Error(message);
    JS_free(cx, message);
    JS_SET_RVAL(cx, vp, JSVAL_VOID);
    return JS_TRUE;
}
开发者ID:donald-hanson,项目名称:battle-of-the-sexes,代码行数:12,代码来源:cg_js_sys.c

示例13: JSVAL_TO_STRING

std::string Context::FromJSArg<std::string>(const JS::Value &val) const
{
  std::string s;
  if(!JSVAL_IS_STRING(val)) {
    return s;
  }
  JSString* jss = JSVAL_TO_STRING(val);
  char* cs = JS_EncodeString(_jsctx, jss);
  s = cs;
  JS_free(_jsctx, cs);
  return s;
}
开发者ID:carriercomm,项目名称:jspp-2,代码行数:12,代码来源:context.cpp

示例14: js_cocos2dx_CCMenuItemFont_create

JSBool js_cocos2dx_CCMenuItemFont_create(JSContext *cx, uint32_t argc, jsval *vp)
{
	if (argc >= 1) {
		jsval *argv = JS_ARGV(cx, vp);
		const char *arg0; do { JSString *tmp = JS_ValueToString(cx, argv[0]); arg0 = JS_EncodeString(cx, tmp); } while (0);
		cocos2d::CCMenuItemFont* ret = cocos2d::CCMenuItemFont::create(arg0);
		JSObject *obj = bind_menu_item<cocos2d::CCMenuItemFont>(cx, ret, (argc == 3 ? argv[2] : JSVAL_VOID), (argc >= 2 ? argv[1] : JSVAL_VOID));
		JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
		return JS_TRUE;
	}
	return JS_FALSE;
}
开发者ID:acc85,项目名称:cocos2d-x,代码行数:12,代码来源:cocos2d_specifics.cpp

示例15: js_cocos2dx_CCMenuItemImage_create

JSBool js_cocos2dx_CCMenuItemImage_create(JSContext *cx, uint32_t argc, jsval *vp)
{
	if (argc >= 2) {
		jsval *argv = JS_ARGV(cx, vp);
		const char *arg0; do { JSString *tmp = JS_ValueToString(cx, argv[0]); arg0 = JS_EncodeString(cx, tmp); } while (0);
		const char *arg1; do { JSString *tmp = JS_ValueToString(cx, argv[1]); arg1 = JS_EncodeString(cx, tmp); } while (0);
		const char *arg2 = NULL;
		int last = 2;
		if (JSVAL_IS_STRING(argv[2])) {
			do { JSString *tmp = JS_ValueToString(cx, argv[2]); arg2 = JS_EncodeString(cx, tmp); } while (0);
			last = 3;
		}
		cocos2d::CCMenuItemImage* ret = cocos2d::CCMenuItemImage::create(arg0, arg1, arg2);
		jsval thisObj = argv[last++];
		jsval callback = argv[last];
		JSObject *obj = bind_menu_item<cocos2d::CCMenuItemImage>(cx, ret, callback, thisObj);
		JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
		return JS_TRUE;
	}
	return JS_FALSE;
}
开发者ID:acc85,项目名称:cocos2d-x,代码行数:21,代码来源:cocos2d_specifics.cpp


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