void potion_source_init(Potion *P) { PN src_vt = PN_VTABLE(PN_TSOURCE); potion_method(src_vt, "compile", potion_source_compile, 0); // in compile.c potion_method(src_vt, "name", potion_source_name, 0); potion_method(src_vt, "string", potion_source_string, 0); potion_method(src_vt, "~link", potion_source__link, 0); }
void Potion_Init_database(Potion *P) { PN db_vt = potion_class(P, 0, 0, 0); PN_TDATABASE = potion_class_type(P, db_vt); potion_define_global(P, PN_STR("Database"), db_vt); potion_type_constructor_is(db_vt, PN_FUNC(potion_sqlite_new, "path=S")); potion_method(db_vt, "exec", potion_sqlite_exec, "query=S|callback=o"); potion_method(db_vt, "gettable", potion_sqlite_gettable, "query=S"); potion_method(db_vt, "close", potion_sqlite_close, 0); potion_method(db_vt, "open", potion_sqlite_open, "path=S"); potion_method(db_vt, "open?", potion_sqlite_isopen, 0); }
void potion_file_init(Potion *P) { PN file_vt = PN_VTABLE(PN_TFILE); char **env = environ, *key; PN pe = potion_table_empty(P); while (*env != NULL) { for (key = *env; *key != '='; key++); potion_table_put(P, PN_NIL, pe, potion_str2(P, *env, key - *env), potion_str(P, key + 1)); env++; } potion_send(P->lobby, PN_def, potion_str(P, "Env"), pe); potion_method(P->lobby, "read", potion_lobby_read, 0); potion_type_constructor_is(file_vt, PN_FUNC(potion_file_new, "path=S,mode=S")); potion_class_method(file_vt, "fd", potion_file_with_fd, "fd=N"); potion_method(file_vt, "string", potion_file_string, 0); potion_method(file_vt, "close", potion_file_close, 0); potion_method(file_vt, "read", potion_file_read, "n=N"); potion_method(file_vt, "write", potion_file_write, "str=S"); }
void potion_error_init(Potion *P) { PN err_vt = PN_VTABLE(PN_TERROR); potion_method(err_vt, "string", potion_error_string, 0); }