Ejemplo n.º 1
0
bool nbdl::Regex::match(const std::string reg, const std::string field)
{ 
	int match = EM_ASM_INT({
		var value = Pointer_stringify($0);
		var regStr = Pointer_stringify($1);
		return value.match(new RegExp(regStr)) !== null;
	}, field.c_str(), reg.c_str());
Ejemplo n.º 2
0
static void printJS(const char *str, int len, void *data) {
	if (len >= 0) {
		char *m = (char *) malloc(len + 1);
		memcpy(m, str, len);
		m[len] = 0;
		//printf(m);
		EM_ASM_( { Module.luaPrint(Pointer_stringify($0)) }, m);
		free(m);
	} else {
		//printf(str);
		EM_ASM_( { Module.luaPrint(Pointer_stringify($0)) }, str);
	}
}
Ejemplo n.º 3
0
static int JSNative_eval(lua_State *L) {

	const char *str=luaL_checkstring(L,-1);

	char *ret=(char *) EM_ASM_INT({
	 return allocate(intArrayFromString(String(eval(Pointer_stringify($0)))), 'i8', ALLOC_STACK);
	},str);
Ejemplo n.º 4
0
int luajs_eval(lua_State *L) {
	const char *str = lua_tostring(L, -1);
	lua_pop(L, 1);
	return EM_ASM_INT({
		LuaJS.__push_var($0, eval(Pointer_stringify($1)));
		return 1;
	}, L, str);
Ejemplo n.º 5
0
		void execute(const char *str)
		{
#ifdef __S3E__
			s3eOSExecExecute(str, false);
#elif __ANDROID__
			jniBrowse(str);
#elif EMSCRIPTEN
			EM_ASM_INT({
				var url = Pointer_stringify($0);
				window.open(url, '_blank');
			}, str);
emscripten_fetch_t *emscripten_fetch(emscripten_fetch_attr_t *fetch_attr, const char *url)
{
	if (!fetch_attr) return 0;
	if (!url) return 0;

	const bool waitable = (fetch_attr->attributes & EMSCRIPTEN_FETCH_WAITABLE) != 0;
	const bool synchronous = (fetch_attr->attributes & EMSCRIPTEN_FETCH_SYNCHRONOUS) != 0;
	const bool readFromIndexedDB = (fetch_attr->attributes & (EMSCRIPTEN_FETCH_APPEND | EMSCRIPTEN_FETCH_NO_DOWNLOAD)) != 0;
	const bool writeToIndexedDB = (fetch_attr->attributes & EMSCRIPTEN_FETCH_PERSIST_FILE) != 0 || !strncmp(fetch_attr->requestMethod, "EM_IDB_", strlen("EM_IDB_"));
	const bool performXhr = (fetch_attr->attributes & EMSCRIPTEN_FETCH_NO_DOWNLOAD) == 0;
	const bool isMainBrowserThread = emscripten_is_main_browser_thread() != 0;
	if (isMainBrowserThread && synchronous && (performXhr || readFromIndexedDB || writeToIndexedDB))
	{
		EM_ASM_INT( { Module['printErr']('emscripten_fetch("' + Pointer_stringify($0) + '") failed! Synchronous blocking XHRs and IndexedDB operations are not supported on the main browser thread. Try dropping the EMSCRIPTEN_FETCH_SYNCHRONOUS flag, or run with the linker flag --proxy-to-worker to decouple main C runtime thread from the main browser thread.') }, 
			url);
		return 0;
	}

	emscripten_fetch_t *fetch = (emscripten_fetch_t *)malloc(sizeof(emscripten_fetch_t));
	memset(fetch, 0, sizeof(emscripten_fetch_t));
	fetch->id = globalFetchIdCounter++; // TODO: make this thread-safe!
	fetch->userData = fetch_attr->userData;
	fetch->url = strdup(url); // TODO: free
	fetch->__attributes = *fetch_attr;
	fetch->__attributes.destinationPath = fetch->__attributes.destinationPath ? strdup(fetch->__attributes.destinationPath) : 0; // TODO: free
	fetch->__attributes.userName = fetch->__attributes.userName ? strdup(fetch->__attributes.userName) : 0; // TODO: free
	fetch->__attributes.password = fetch->__attributes.password ? strdup(fetch->__attributes.password) : 0; // TODO: free
	fetch->__attributes.requestHeaders = 0;// TODO:strdup(fetch->__attributes.requestHeaders);
	fetch->__attributes.overriddenMimeType = fetch->__attributes.overriddenMimeType ? strdup(fetch->__attributes.overriddenMimeType) : 0; // TODO: free

#if __EMSCRIPTEN_PTHREADS__
	// Depending on the type of fetch, we can either perform it in the same Worker/thread than the caller, or we might need
	// to run it in a separate Worker. There is a dedicated fetch worker that is available for the fetch, but in some scenarios
	// it might be desirable to run in the same Worker as the caller, so deduce here whether to run the fetch in this thread,
	// or if we need to use the fetch-worker instead.
	if (waitable // Waitable fetches can be synchronously waited on, so must always be proxied
		|| (synchronous && (readFromIndexedDB || writeToIndexedDB))) // Synchronous IndexedDB access needs proxying
	{
		emscripten_atomic_store_u32(&fetch->__proxyState, 1); // sent to proxy worker.
		emscripten_proxy_fetch(fetch);

		if (synchronous) emscripten_fetch_wait(fetch, INFINITY);
	}
	else
#endif
		emscripten_start_fetch(fetch);
	return fetch;
}
Ejemplo n.º 7
0
    void emscStartSoundsPreloading(Resources& resources)
    {
#ifdef EMSCRIPTEN
        Resources::resources lst;
        resources.collect(lst);
        for (size_t i = 0; i < lst.size(); ++i)
        {
            ResSound* rs = dynamic_cast<ResSound*>(lst[i].get());
            if (!rs)
                continue;

            EM_ASM_ARGS(
            {
                var p = Preloading("hello");
                p.add(Pointer_stringify($0));
                p.start();
            }, rs->getPath().c_str());
        }
Ejemplo n.º 8
0
int luajs_jsobject__index(lua_State *L) {
	const char *val = lua_tostring(L, -1);
	lua_pop(L, 1);
	
	GET_TypedPointerData();
	
	jslua_get_metatable(L, data->type);
	lua_pushstring(L, val);
	
	lua_rawget(L, -2);
	lua_remove(L, 1);
	lua_remove(L, 1);
	
	if(lua_isnil(L, -1))
		lua_pop(L, 1);
	else
		return 1;
	
	return EM_ASM_INT({
		$2 = Pointer_stringify($2);
		var val = LuaJS.__get_var_by_ref($1);
		LuaJS.__push_var($0, val[$2]);
		return 1;
	}, L, data->ptr, val);
Ejemplo n.º 9
0
int GetCacheMesTextureID( char *msg, int font_size, int font_style )
{
	//		キャッシュ済みのテクスチャIDを返す(OpenGLテクスチャIDを返す)
	//		(作成されていないメッセージテクスチャは自動的に作成する)
	//		(作成の必要がない場合は-1を返す)
	//
#ifdef HSPNDK
	GLuint id;
	int texid;
	int tsx,tsy;
	unsigned char *pImg;

	TEXINF *t;
	int mylen;
	short mycache;
	
	mycache = str2hash( msg, &mylen );			// キャッシュを取得
	if ( mylen <= 0 ) return -1;

	texid = getCache( msg, mycache, font_size, font_style );
	if ( texid >= 0 ) {
		return texid;							// キャッシュがあった
	}

	//		キャッシュが存在しないので作成
	pImg = (unsigned char *)j_callFontBitmap( msg, font_size, font_style, &tsx, &tsy );
	texid = MakeEmptyTex( tsx, tsy );
	if ( texid < 0 ) return -1;

	t = GetTex( texid );
	t->hash = mycache;
	t->font_size = font_size;
	t->font_style = font_style;

	if ( curmestex >= GetSysReq(SYSREQ_MESCACHE_MAX) ) {	// エントリ数がオーバーしているものは次のフレームで破棄
		t->life = 0;
		t->buf[0] = 0;
	} else {
		//		キャッシュの登録
		if ( mylen >= ( TEXMES_NAME_BUFFER - 1 ) ) {
			t->text = (char *)malloc( mylen+1 );		// テキストハッシュネーム用バッファを作成する
			strcpy( t->text, msg );
		} else {
			strcpy( t->buf, msg );						// 標準バッファにコピーする
		}
	}

	id = (GLuint)t->texid;

	glBindTexture( GL_TEXTURE_2D, id );
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	glPixelStorei( GL_UNPACK_ALIGNMENT, 1);

	glTexSubImage2D(
		GL_TEXTURE_2D,
		0,
		(GLint)0,
		(GLint)0,
		(GLsizei)tsx,
		(GLsizei)tsy,
		GL_ALPHA,
		GL_UNSIGNED_BYTE,
		pImg
	);

	glBindTexture(GL_TEXTURE_2D, 0);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

	free(pImg);

	return texid;
#endif

#ifdef HSPEMSCRIPTEN
	GLuint id;
	int texid;
	int tsx,tsy;
	unsigned char *pImg;

	TEXINF *t;
	int mylen;
	short mycache;

	mycache = str2hash( msg, &mylen );			// キャッシュを取得
	if ( mylen <= 0 ) return -1;

	texid = getCache( msg, mycache, font_size, font_style );
	if ( texid >= 0 ) {
		return texid;							// キャッシュがあった
	}

	EM_ASM_({
		var d = document.getElementById('hsp3dishFontDiv');
		if (!d) {
			d = document.createElement("div");
			d.id = 'hsp3dishFontDiv';
			d.style.setProperty("width", "auto");
			d.style.setProperty("height", "auto");
			d.style.setProperty("position", "absolute");
			d.style.setProperty("visibility", "hidden");
		}
		d.style.setProperty("font", $1 + "px 'sans-serif'");
		document.body.appendChild(d);

		var t = document.createTextNode(Pointer_stringify($0));
		if (d.hasChildNodes())
			d.removeChild(d.firstChild);
		d.appendChild(t);
		}, msg, font_size);
Ejemplo n.º 10
0
void AppendLogBuffer(bool checkDuplicate, std::string message)
{
    if (checkDuplicate && LogBufferContains(message)) return;
    logBuffer.push_back(message);
    EM_ASM_ARGS({ console.log(Pointer_stringify($0)); }, message.c_str());