static void knh_linkDynamicReadline(CTX ctx) { if(ctx->spi->readline == NULL) { void *handler = knh_dlopen(ctx, "libreadline" K_OSDLLEXT); if(handler != NULL) { void *f = knh_dlsym(ctx, handler, "readline", NULL, 0/*isTest*/); if(f != NULL) { ((knh_ServiceSPI_t*)ctx->spi)->readlinespi = "libreadline"; ((knh_ServiceSPI_t*)ctx->spi)->readline = (char* (*)(const char*))f; } else { goto L_STDIN; } f = knh_dlsym(ctx, handler, "add_history", NULL, 0/*isTest*/); if(f != NULL) { ((knh_ServiceSPI_t*)ctx->spi)->add_history = (int (*)(const char*))f; } else { ((knh_ServiceSPI_t*)ctx->spi)->add_history = add_history; } return; } L_STDIN:; ((knh_ServiceSPI_t*)ctx->spi)->readlinespi = "stdin"; ((knh_ServiceSPI_t*)ctx->spi)->readline = readline; ((knh_ServiceSPI_t*)ctx->spi)->add_history = add_history; } }
static void knh_linkDynamicIconv(CTX ctx) { knh_ServiceSPI_t *spi = ((knh_ServiceSPI_t*)ctx->spi); void *handler = knh_dlopen(ctx, "libiconv" K_OSDLLEXT); void *f = NULL; if(handler != NULL) { f = knh_dlsym(ctx, handler, "iconv_open", "libiconv_open", 1/*isTest*/); if (f != NULL) { spi->iconvspi = "libiconv"; spi->iconv_openSPI = (ficonv_open)f; spi->iconvSPI = (ficonv)knh_dlsym(ctx, handler, "iconv", "libiconv", 0/*isTest*/); spi->iconv_closeSPI = (ficonv_close)knh_dlsym(ctx, handler, "libiconv_close", "iconv_close", 0); KNH_ASSERT(spi->iconvSPI != NULL && spi->iconv_closeSPI != NULL); return ; // OK } } PleaseLetUsKnowYourOS("libiconv is not available"); }
knh_Fmethod knh_gluefunc(CTX ctx, kMethod *mtd, kNameSpace *ns, kDictMap *mdata) { knh_Fmethod gluefunc = NULL; kObject *gluedata = knh_DictMap_getNULL(ctx, mdata, STEXT("gluefunc")); if(gluedata != NULL && IS_bString(gluedata)) { if(ns->gluehdr == NULL) { DBG_P("gluehdr is not open"); } else { gluefunc = (knh_Fmethod)knh_dlsym(ctx, ns->gluehdr, S_totext((kString*)gluedata), NULL, 0); if(gluefunc == NULL) { DBG_P("gluefunc is not found: %s", S_totext((kString*)gluedata)); } } } //if(gluefunc == NULL) { // gluefunc = Fmethod_FFI; //} return gluefunc; }
static void load_codegenerator(CTX ctx) { KONOHA_BEGIN(ctx); CompilerAPI_disable(ctx); if (codegenerator_file[compile_mode]) { kbytes_t t = new_bytes((char*)codegenerator_file[compile_mode]); knh_loadPackage(ctx, t); CWB_t cwbbuf, *cwb = CWB_open(ctx, &cwbbuf); kString *s = (kString *) knh_DictMap_getNULL(ctx, ctx->share->props, STEXT("konoha.package.path")); CWB_clear(cwb, 0); knh_buff_addpath(ctx, cwb->ba, cwb->pos, 0, S_tobytes(s)); knh_buff_addpath(ctx, cwb->ba, cwb->pos, 1, STEXT("konoha.compiler")); knh_buff_addpath(ctx, cwb->ba, cwb->pos, 1, STEXT("compiler")); knh_buff_addpath(ctx, cwb->ba, cwb->pos, 0, STEXT(K_OSDLLEXT)); void *p = knh_dlopen(ctx, CWB_totext(ctx, cwb)); typedef void (*knh_Fpkgcomplete)(CTX); knh_Fpkgcomplete pkgcomplete = (knh_Fpkgcomplete) knh_dlsym(ctx, p, "reset_compiler_api", NULL, 1); if (pkgcomplete) pkgcomplete(ctx); CWB_close(ctx, cwb); } CompilerAPI_enable(ctx); KONOHA_END(ctx); }