} return rc; } static SQRESULT sq_libclang_loadlib(HSQUIRRELVM v) { SQ_FUNC_VARS_NO_TOP(v); SQ_GET_STRING(v, 2, libname); sq_pushbool(v, load_dynamicLib(libname)); return 1; } #define _DECL_FUNC(name,nparams,tycheck) {_SC(#name), sq_libclang_##name,nparams,tycheck} static SQRegFunction sq_libclang_methods[] = { _DECL_FUNC(constructor, 1, _SC("x")), _DECL_FUNC(close, 1, _SC("x")), _DECL_FUNC(parseTranslationUnit, -3, _SC("xcs")), _DECL_FUNC(loadlib,2,_SC(".s")), {0,0} }; #undef _DECL_FUNC #ifdef __cplusplus extern "C" { #endif SQRESULT sqext_register_libclang(HSQUIRRELVM v) { sq_pushstring(v,LibClang_TAG,-1);
SINGLE_ARG_FUNC(cos) SINGLE_ARG_FUNC(asin) SINGLE_ARG_FUNC(acos) SINGLE_ARG_FUNC(log) SINGLE_ARG_FUNC(log10) SINGLE_ARG_FUNC(tan) SINGLE_ARG_FUNC(atan) TWO_ARGS_FUNC(atan2) TWO_ARGS_FUNC(pow) SINGLE_ARG_FUNC(floor) SINGLE_ARG_FUNC(ceil) SINGLE_ARG_FUNC(exp) #define _DECL_FUNC(name,nparams,tycheck) {_SC(#name),math_##name,nparams,tycheck} static SQRegFunction mathlib_funcs[] = { _DECL_FUNC(sqrt,2,_SC(".n")), _DECL_FUNC(sin,2,_SC(".n")), _DECL_FUNC(cos,2,_SC(".n")), _DECL_FUNC(asin,2,_SC(".n")), _DECL_FUNC(acos,2,_SC(".n")), _DECL_FUNC(log,2,_SC(".n")), _DECL_FUNC(log10,2,_SC(".n")), _DECL_FUNC(tan,2,_SC(".n")), _DECL_FUNC(atan,2,_SC(".n")), _DECL_FUNC(atan2,3,_SC(".nn")), _DECL_FUNC(pow,3,_SC(".nn")), _DECL_FUNC(floor,2,_SC(".n")), _DECL_FUNC(ceil,2,_SC(".n")), _DECL_FUNC(exp,2,_SC(".n")), _DECL_FUNC(srand,2,_SC(".n")), _DECL_FUNC(rand,1,NULL),
dlmysql_data_seek(self, row); const MYSQL_ROW res_row = dlmysql_fetch_row(self); unsigned long *lengths = dlmysql_fetch_lengths(self); MYSQL_FIELD *fields = dlmysql_fetch_fields(self); for(int i=0; i < col_count; ++i){ sq_pushstring(v, fields[i].name, -1); sq_pushstring(v, (const SQChar*)res_row[i], lengths[i]); sq_rawset(v, -3); } return 1; } #define _DECL_FUNC(name,nparams,tycheck) {_SC(#name), sq_mysql_result_##name,nparams,tycheck} static SQRegFunction sq_mysql_result_methods[] = { _DECL_FUNC(close, 1, _SC("x")), _DECL_FUNC(eof, 1, _SC("x")), _DECL_FUNC(next_row, 1, _SC("x")), _DECL_FUNC(col_count, 1, _SC("x")), _DECL_FUNC(row_count, 1, _SC("x")), _DECL_FUNC(col_name, 2, _SC("xi")), _DECL_FUNC(col_index, 2, _SC("xs")), _DECL_FUNC(col_value, 2, _SC("x i|s")), _DECL_FUNC(row_as_array, -1, _SC("xi")), _DECL_FUNC(row_as_table, -1, _SC("xi")), {0,0} }; #undef _DECL_FUNC struct SQ_MysqlStatement {
_set_integer_slot(v, _SC("sec"), date->tm_sec); _set_integer_slot(v, _SC("min"), date->tm_min); _set_integer_slot(v, _SC("hour"), date->tm_hour); _set_integer_slot(v, _SC("day"), date->tm_mday); _set_integer_slot(v, _SC("month"), date->tm_mon); _set_integer_slot(v, _SC("year"), date->tm_year+1900); _set_integer_slot(v, _SC("wday"), date->tm_wday); _set_integer_slot(v, _SC("yday"), date->tm_yday); return 1; } #define _DECL_FUNC(name,nparams,pmask) {_SC(#name),_system_##name,nparams,pmask} static const SQRegFunction systemlib_funcs[]={ _DECL_FUNC(getenv,2,_SC(".s")), _DECL_FUNC(system,2,_SC(".s")), _DECL_FUNC(clock,0,NULL), _DECL_FUNC(time,1,NULL), _DECL_FUNC(date,-1,_SC(".nn")), _DECL_FUNC(remove,2,_SC(".s")), _DECL_FUNC(rename,3,_SC(".ss")), {NULL,(SQFUNCTION)0,0,NULL} }; #undef _DECL_FUNC SQInteger sqstd_register_systemlib(HSQUIRRELVM v) { SQInteger i=0; while(systemlib_funcs[i].name!=0) {
} #define _DECL_REX_FUNC(name,nparams,pmask) {_SC(#name),_regexp_##name,nparams,pmask} static SQRegFunction rexobj_funcs[] = { _DECL_REX_FUNC( constructor, 2, _SC( ".s" ) ), _DECL_REX_FUNC( search, -2, _SC( "xsn" ) ), _DECL_REX_FUNC( match, 2, _SC( "xs" ) ), _DECL_REX_FUNC( capture, -2, _SC( "xsn" ) ), _DECL_REX_FUNC( subexpcount, 1, _SC( "x" ) ), _DECL_REX_FUNC( _typeof, 1, _SC( "x" ) ), {0, 0} }; #define _DECL_FUNC(name,nparams,pmask) {_SC(#name),_string_##name,nparams,pmask} static SQRegFunction stringlib_funcs[] = { _DECL_FUNC( format, -2, _SC( ".s" ) ), {0, 0} }; SQInteger sqstd_register_stringlib( HSQUIRRELVM v ) { sq_pushstring( v, _SC( "regexp" ), -1 ); sq_newclass( v, SQFalse ); SQInteger i = 0; while ( rexobj_funcs[i].name != 0 ) { SQRegFunction &f = rexobj_funcs[i]; sq_pushstring( v, f.name, -1 ); sq_newclosure( v, f.f, 0 ); sq_setparamscheck( v, f.nparamscheck, f.typemask ); sq_setnativeclosurename( v, -1, f.name ); sq_createslot( v, -3 );
} static SQRESULT sq_minizip_unzip_destroy(HSQUIRRELVM v) { SQ_FUNC_VARS_NO_TOP(v); GET_minizip_unzip_INSTANCE(); int rc = sq_minizip_unzip_releasehook(self, 0, v); if(rc == 0) sq_setinstanceup(v, 1, 0); sq_pushinteger(v, rc); return 1; } #define _DECL_FUNC(name,nparams,tycheck) {_SC(#name), sq_minizip_unzip_##name,nparams,tycheck} static SQRegFunction sq_minizip_unzip_methods[] = { _DECL_FUNC(constructor, 2, _SC("xs")), _DECL_FUNC(get_num_files, 1, _SC("x")), _DECL_FUNC(goto_first_file, 1, _SC("x")), _DECL_FUNC(goto_next_file, 1, _SC("x")), _DECL_FUNC(get_file_info, 1, _SC("x")), _DECL_FUNC(extract_file, 1, _SC("x")), _DECL_FUNC(destroy, 1, _SC("x")), {0,0} }; #undef _DECL_FUNC static SQRESULT sq_check_result(HSQUIRRELVM v, int result, const z_stream* stream) { /* Both of these are "normal" return codes: */ if ( result == Z_OK || result == Z_STREAM_END ) return SQ_OK; switch ( result ) {
} #define _DECL_REX_FUNC(name,nparams,pmask) {_SC(#name),_regexp_##name,nparams,pmask} static SQRegFunction rexobj_funcs[]={ _DECL_REX_FUNC(constructor,2,_SC(".s")), _DECL_REX_FUNC(search,-2,_SC("xsn")), _DECL_REX_FUNC(match,2,_SC("xs")), _DECL_REX_FUNC(capture,-2,_SC("xsn")), _DECL_REX_FUNC(subexpcount,1,_SC("x")), _DECL_REX_FUNC(_typeof,1,_SC("x")), {0,0} }; #define _DECL_FUNC(name,nparams,pmask) {_SC(#name),_string_##name,nparams,pmask} static SQRegFunction stringlib_funcs[]={ _DECL_FUNC(format,-2,_SC(".s")), _DECL_FUNC(strip,2,_SC(".s")), _DECL_FUNC(lstrip,2,_SC(".s")), _DECL_FUNC(rstrip,2,_SC(".s")), _DECL_FUNC(split,3,_SC(".ss")), {0,0} }; SQInteger sqstd_register_stringlib(HSQUIRRELVM v) { sq_pushstring(v,_SC("regexp"),-1); sq_newclass(v,SQFalse); SQInteger i = 0; while(rexobj_funcs[i].name != 0) { SQRegFunction &f = rexobj_funcs[i];
sq_pushinteger(v, *(int*)pval); } return 1; } static SQInteger sq_ffi_setdelegate(HSQUIRRELVM v) { if (SQ_FAILED(sq_setdelegate(v, 2))) return SQ_ERROR; return 0; } #define _DECL_FUNC(name,nparams,tycheck) {_SC(#name), sq_ffi_##name,nparams,tycheck} static SQRegFunction sq_ffi_methods[] = { _DECL_FUNC(load, 2, _SC(".s")), _DECL_FUNC(sym, 3, _SC(".ps")), _DECL_FUNC(setdelegate, 3, _SC("..t")), {0,0} }; #undef _DECL_FUNC #define _DECL_FUNC(name,nparams,tycheck) {_SC(#name), sq_lib_##name,nparams,tycheck} static SQRegFunction sq_lib_methods[] = { _DECL_FUNC(bind_func, 4, _SC("ussa")), _DECL_FUNC(bind_var, 3, _SC("uss")), {0,0} }; #undef _DECL_FUNC
if (SUCCEED!=mkdir(s, 0777)) { sprintf(err, "mkdir failed: %d:%s", errno, strerror(errno)); return ps_throwerror(v,err); } } return 1; } return 0; } #define _DECL_FUNC(name,nparams,pmask) {_SC(#name),_exutil_##name,nparams,pmask} static PSRegFunction exutillib_funcs[]={ _DECL_FUNC(getline,1,_SC(".s")), _DECL_FUNC(getcwd,1,_SC(".s")), _DECL_FUNC(getosname,1,_SC(".s")), _DECL_FUNC(userlog,2,_SC(".s")), _DECL_FUNC(mkdir,2,_SC(".s")), _DECL_FUNC(chmod,3,_SC(".ss")), {0,0} }; #undef _DECL_FUNC PSInteger psstd_register_exutillib(HPSCRIPTVM v) { PSInteger i=0; while(exutillib_funcs[i].name!=0) { ps_pushstring(v,exutillib_funcs[i].name,-1);
MD5_CTX ctx; MD5Init(&ctx); for (int i = 2; i <= _top_; ++i) { SQ_GET_STRING(v, i, p); MD5Update(&ctx, (const unsigned char *) p, p_size); } MD5Final(hash, &ctx); DigestToBase16(hash, buf, hash_size); sq_pushstring(v, buf, buf_size); return 1; } #define _DECL_FUNC(name,nparams,pmask) {_SC(#name), sq_fossil_##name,nparams,pmask} static SQRegFunction fossil_obj_funcs[]={ _DECL_FUNC(delta_create,3, _SC(".ss")), _DECL_FUNC(delta_apply,3, _SC(".ss")), _DECL_FUNC(delta_output_size,2, _SC(".s")), _DECL_FUNC(delta_analyze,2, _SC(".s")), _DECL_FUNC(sha3sum,-3, _SC(".is")), _DECL_FUNC(sha1sum,-2, _SC(".s")), _DECL_FUNC(md5sum,-2, _SC(".s")), {0,0} }; #undef _DECL_FUNC #ifdef __cplusplus extern "C" { #endif /* This defines a function that opens up your library. */ SQRESULT sqext_register_fossil (HSQUIRRELVM sqvm) {
size_t start, pos; SQBlob b(0, BLOB_BUFSIZE); for(start=pos=0; s[pos]!=0; ++pos) if(s[pos]<0) { if(pos>start) b.Write(s+start, pos-start); b.WriteZstr(char2code(uchar(s[pos]),buf)); start=pos+1; } if(pos>start) b.Write(s+start, pos-start); sq_pushstring(v, (const SQChar*)b.GetBuf(), b.Len()); return 1; } #define _DECL_FUNC(name,nparams,tycheck) {_SC(#name),base64_##name,nparams,tycheck} static SQRegFunction xml_methods[] = { _DECL_FUNC(load,2,_SC(".s")), _DECL_FUNC(eval,2,_SC(".s")), _DECL_FUNC(encode,2,_SC(".s")), _DECL_FUNC(registerCode,2,_SC(".s")), {0,0} }; #ifdef __cplusplus extern "C" { #endif SQRESULT sqext_register_sqxml(HSQUIRRELVM v) { sq_pushstring(v,_SC("SQXml"),-1); sq_newclass(v,SQFalse); sq_insert_reg_funcs(v, xml_methods);
sprintf(fullname,"%s",fname); else sprintf(fullname,"%s/%s",__pSQ->ctx()->_dir_home,fname); FILE* pf = fopen(fullname, "ab"); if(!pf) {return sq_throwerror(v,_SC("fopen(null_pointer, 0 bytes) error"));} str_time(tmm); fprintf(pf,"[%s] \t%s\n", tmm, text); fclose(pf); return 1; } return -1; } #define _DECL_FUNC(name,nparams,pmask) {_SC(#name),_mod_##name,nparams,pmask} static SQRegFunction global_funcs[]= { _DECL_FUNC(echo,2,_SC(".s")), // _this.write _DECL_FUNC(header,2,_SC(".s")), // _this.write _DECL_FUNC(cookie,4,_SC(".ssn")), // _this.write _DECL_FUNC(br,1,NULL), // _this.write _DECL_FUNC(fopen,3, _SC(".ss")), _DECL_FUNC(fclose,2,_SC(".p")), _DECL_FUNC(fread,3,_SC(".pn")), _DECL_FUNC(fwrite,3,_SC(".ps")), _DECL_FUNC(fseek,4,_SC(".snn")), _DECL_FUNC(ftell,2,_SC(".p")), _DECL_FUNC(fsize,2,_SC(".p")), _DECL_FUNC(fgets,2,_SC(".p")), // _DECL_FUNC(readfile,3,_SC(".sn")), _DECL_FUNC(filesize,2,_SC(".s")), _DECL_FUNC(filestrstr,3,_SC(".ss")),
#define _DECL_REX_FUNC(name,nparams,pmask,help) {_SC(#name),_regexp_##name,nparams,pmask,__FILE__,_SC(help)} static SQRegFunction rexobj_funcs[]={ _DECL_REX_FUNC(constructor,2,_SC(".s"), "(pattern: string): regex"), _DECL_REX_FUNC(search,-2,_SC("xsn"), "(string, [start: int]): {begin=?, end=?}"), _DECL_REX_FUNC(match,2,_SC("xs"), "(string): bool"), _DECL_REX_FUNC(capture,-2,_SC("xsn"), "(string, [start: int]): array of { begin=?, end=? }"), _DECL_REX_FUNC(subexpcount,1,_SC("x"), "(): int"), _DECL_REX_FUNC(_typeof,1,_SC("x"), NULL), _DECL_REX_FUNC(help,1,_SC("."), NULL), {0,0} }; #define _DECL_FUNC(name,nparams,pmask,help) {_SC(#name),_string_##name,nparams,pmask,__FILE__,_SC(help)} static SQRegFunction stringlib_funcs[]={ _DECL_FUNC(format,-2,_SC(".s"), "(fmt: string, ...): string"), {0,0} }; static SQRegFunction stringextdeleg_funcs[]={ _DECL_FUNC(strip,1,_SC("s"), "(): string"), _DECL_FUNC(lstrip,1,_SC("s"), "(): string"), _DECL_FUNC(rstrip,1,_SC("s"), "(): string"), _DECL_FUNC(split,2,_SC("ss"), "(separators: string): string[]"), {0,0} }; SQInteger sqstd_register_stringlib(HSQUIRRELVM v) { sq_pushstring(v,_SC("regexp"),-1); sq_newclass(v,SQFalse,"regexp");
#define _DECL_REX_FUNC(name,nparams,pmask) {_SC(#name),_regexp_##name,nparams,pmask} static const SQRegFunction rexobj_funcs[]={ _DECL_REX_FUNC(constructor,2,_SC(".s")), _DECL_REX_FUNC(search,-2,_SC("xsn")), _DECL_REX_FUNC(match,2,_SC("xs")), _DECL_REX_FUNC(capture,-2,_SC("xsn")), _DECL_REX_FUNC(subexpcount,1,_SC("x")), _DECL_REX_FUNC(_typeof,1,_SC("x")), {NULL,(SQFUNCTION)0,0,NULL} }; #undef _DECL_REX_FUNC #define _DECL_FUNC(name,nparams,pmask) {_SC(#name),_string_##name,nparams,pmask} static const SQRegFunction stringlib_funcs[]={ _DECL_FUNC(format,-2,_SC(".s")), _DECL_FUNC(printf,-2,_SC(".s")), _DECL_FUNC(strip,2,_SC(".s")), _DECL_FUNC(lstrip,2,_SC(".s")), _DECL_FUNC(rstrip,2,_SC(".s")), _DECL_FUNC(split,3,_SC(".ss")), _DECL_FUNC(escape,2,_SC(".s")), _DECL_FUNC(startswith,3,_SC(".ss")), _DECL_FUNC(endswith,3,_SC(".ss")), {NULL,(SQFUNCTION)0,0,NULL} }; #undef _DECL_FUNC SQInteger sqstd_register_stringlib(HSQUIRRELVM v) {