- if (NSMutableArray *entry = [[Bridge_ objectAtIndex:0] objectForKey:name])
- switch ([[entry objectAtIndex:0] intValue]) {
- case 0:
- return JSEvaluateScript(CYGetJSContext(), CYJSString([entry objectAtIndex:1]), NULL, NULL, 0, NULL);
- case 1:
- return CYMakeFunctor(context, reinterpret_cast<void (*)()>([name cy$symbol]), CYPoolCString(pool, [entry objectAtIndex:1]));
- case 2:
- // XXX: this is horrendously inefficient
- sig::Signature signature;
- sig::Parse(pool, &signature, CYPoolCString(pool, [entry objectAtIndex:1]), &Structor_);
- ffi_cif cif;
- sig::sig_ffi_cif(pool, &sig::ObjectiveC, &signature, &cif);
- return CYFromFFI(context, signature.elements[0].type, cif.rtype, [name cy$symbol]);
- }
- if (NSMutableArray *entry = [[Bridge_ objectAtIndex:2] objectForKey:name])
- switch ([[entry objectAtIndex:0] intValue]) {
- // XXX: implement case 0
- case 1:
- return CYMakeType(context, CYPoolCString(pool, [entry objectAtIndex:1]));
+#endif
+
+ sqlite3_stmt *statement;
+
+ _sqlcall(sqlite3_prepare(Bridge_,
+ "select "
+ "\"bridge\".\"mode\", "
+ "\"bridge\".\"value\" "
+ "from \"bridge\" "
+ "where"
+ " \"bridge\".\"name\" = ?"
+ " limit 1"
+ , -1, &statement, NULL));
+
+ _sqlcall(sqlite3_bind_text(statement, 1, name, -1, SQLITE_STATIC));
+
+ int mode;
+ const char *value;
+
+ if (_sqlcall(sqlite3_step(statement)) == SQLITE_DONE) {
+ mode = -1;
+ value = NULL;
+ } else {
+ mode = sqlite3_column_int(statement, 0);
+ value = sqlite3_column_pooled(pool, statement, 1);
+ }
+
+ _sqlcall(sqlite3_finalize(statement));
+
+ switch (mode) {
+ default:
+ _assert(false);
+ case -1:
+ return NULL;
+
+ case 0:
+ return JSEvaluateScript(CYGetJSContext(), CYJSString(value), NULL, NULL, 0, NULL);
+ case 1:
+ return CYMakeFunctor(context, reinterpret_cast<void (*)()>(CYCastSymbol(name)), value);
+
+ case 2: {
+ // XXX: this is horrendously inefficient
+ sig::Signature signature;
+ sig::Parse(pool, &signature, value, &Structor_);
+ ffi_cif cif;
+ sig::sig_ffi_cif(pool, &sig::ObjectiveC, &signature, &cif);
+ return CYFromFFI(context, signature.elements[0].type, cif.rtype, CYCastSymbol(name));