return CYMakeType(context, &type);
}
-extern "C" const char *CYBridgeHash(CYPool &pool, CYUTF8String name) {
+extern "C" bool CYBridgeHash(CYPool &pool, CYUTF8String name, const char *&code, unsigned &flags) {
sqlite3_stmt *statement;
_sqlcall(sqlite3_prepare(database_,
"select "
- "\"cache\".\"value\" "
+ "\"cache\".\"code\", "
+ "\"cache\".\"flags\" "
"from \"cache\" "
"where"
" \"cache\".\"system\" & " CY_SYSTEM " == " CY_SYSTEM " and"
_sqlcall(sqlite3_bind_text(statement, 1, name.data, name.size, SQLITE_STATIC));
- const char *value;
+ bool success;
if (_sqlcall(sqlite3_step(statement)) == SQLITE_DONE)
- value = NULL;
- else
- value = sqlite3_column_pooled(pool, statement, 0);
+ success = false;
+ else {
+ success = true;
+ code = sqlite3_column_pooled(pool, statement, 0);
+ flags = sqlite3_column_int(statement, 1);
+ }
_sqlcall(sqlite3_finalize(statement));
- return value;
+ return success;
}
static bool All_hasProperty(JSContextRef context, JSObjectRef object, JSStringRef property) {
return true;
CYPool pool;
- if (CYBridgeHash(pool, CYPoolUTF8String(pool, context, property)) != NULL)
+ const char *code;
+ unsigned flags;
+ if (CYBridgeHash(pool, CYPoolUTF8String(pool, context, property), code, flags))
return true;
return false;
return value;
CYPool pool;
- if (const char *code = CYBridgeHash(pool, CYPoolUTF8String(pool, context, property))) {
- JSValueRef result(_jsccall(JSEvaluateScript, context, CYJSString(CYPoolCode(pool, code)), NULL, NULL, 0));
- JSObjectRef cache(CYGetCachedObject(context, CYJSString("cache")));
- CYSetProperty(context, cache, property, result);
+ const char *code;
+ unsigned flags;
+ if (CYBridgeHash(pool, CYPoolUTF8String(pool, context, property), code, flags)) {
+ CYUTF8String parsed;
+
+ try {
+ parsed = CYPoolCode(pool, code);
+ } catch (const CYException &error) {
+ CYThrow("%s", pool.strcat("error caching ", CYPoolCString(pool, context, property), ": ", error.PoolCString(pool), NULL));
+ }
+
+ JSValueRef result(_jsccall(JSEvaluateScript, context, CYJSString(parsed), NULL, NULL, 0));
+
+ if (flags == 0) {
+ JSObjectRef cache(CYGetCachedObject(context, CYJSString("cache")));
+ CYSetProperty(context, cache, property, result);
+ }
+
return result;
}
sqlite3_stmt *statement;
- _sqlcall(sqlite3_prepare(database_,
- "select "
- "\"cache\".\"name\" "
- "from \"cache\" "
- "where"
- " \"cache\".\"system\" & " CY_SYSTEM " == " CY_SYSTEM " and"
- " \"cache\".\"name\" like ? || '%'"
- , -1, &statement, NULL));
-
- _sqlcall(sqlite3_bind_text(statement, 1, prefix.data, prefix.size, SQLITE_STATIC));
+ if (prefix.size == 0)
+ _sqlcall(sqlite3_prepare(database_,
+ "select "
+ "\"cache\".\"name\" "
+ "from \"cache\" "
+ "where"
+ " \"cache\".\"system\" & " CY_SYSTEM " == " CY_SYSTEM
+ , -1, &statement, NULL));
+ else {
+ _sqlcall(sqlite3_prepare(database_,
+ "select "
+ "\"cache\".\"name\" "
+ "from \"cache\" "
+ "where"
+ " \"cache\".\"name\" >= ? and \"cache\".\"name\" < ? and "
+ " \"cache\".\"system\" & " CY_SYSTEM " == " CY_SYSTEM
+ , -1, &statement, NULL));
+
+ _sqlcall(sqlite3_bind_text(statement, 1, prefix.data, prefix.size, SQLITE_STATIC));
+
+ char *after(pool.strndup(prefix.data, prefix.size));
+ ++after[prefix.size - 1];
+ _sqlcall(sqlite3_bind_text(statement, 2, after, prefix.size, SQLITE_STATIC));
+ }
while (_sqlcall(sqlite3_step(statement)) != SQLITE_DONE)
values.push_back(CYCastJSValue(context, CYJSString(sqlite3_column_string(statement, 0))));
_assert(slash != NULL);
*slash = '\0';
+ slash = strrchr(lib, '/');
+ if (slash != NULL && strcmp(slash, "/.libs") == 0)
+ *slash = '\0';
+
return lib;
}
static bool CYRunScript(JSGlobalContextRef context, const char *path) {
CYPool pool;
- CYUTF8String code(CYPoolFileUTF8String(pool, path));
+ CYUTF8String code(CYPoolFileUTF8String(pool, pool.strcat(CYPoolLibraryPath(pool), path, NULL)));
if (code.data == NULL)
return false;
CYArrayPush(context, alls, cycript);
- CYRunScript(context, "libcycript.cy");
+ CYRunScript(context, "/libcycript.cy");
}
static JSGlobalContextRef context_;