开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
开源项目 > 程序开发 > 编程语言/脚本语言 &&
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
13 Star 69 Fork 22

johnsonyl/cpps

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
v1.0.2
分支 (1)
标签 (4)
master
v1.0.3-beta
v1.0.3
v1.0.2
v1.0.0
v1.0.2
分支 (1)
标签 (4)
master
v1.0.3-beta
v1.0.3
v1.0.2
v1.0.0
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
v1.0.2
分支 (1)
标签 (4)
master
v1.0.3-beta
v1.0.3
v1.0.2
v1.0.0
cpps
/
src
/
cpps_base.cpp
cpps
/
src
/
cpps_base.cpp
cpps_base.cpp 25.10 KB
一键复制 编辑 原始数据 按行查看 历史
johnsonyl 提交于 2023年12月07日 18:15 +08:00 . 增加operator ()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034
#include "cpps/cpps.h"
using namespace std;
namespace cpps
{
void cpps_console_clearcolor();
void cpps_console_color(cpps_integer color);
bool cpps_io_file_exists(std::string path);
void cpps_load_filebuffer(const char* path, std::string& fileSrc);
std::string getfilenamenotext(std::string str);
std::string cpps_rebuild_filepath(std::string path);
cpps_integer cpps_math_rand();
bool cpps_isbasevar(const cpps_value& v);
bool cpps_io_isdir(std::string p);
void cpps_debug_trace_domain(C* c, int kg, std::string parent, cpps_domain* root);
std::string cpps_io_getfilepath(std::string str);
bool cpps_base_isdebug() {
#ifdef _DEBUG
return true;
#else
return false;
#endif
}
bool cpps_base_isvalid(cpps_value v)
{
return v.tt != CPPS_TNIL;
}
cpps_integer cpps_base_len(object b)
{
cpps_integer ret = 0;
if (type(b) == CPPS_TSTRING)
{
std::string* s = cpps_get_string(b.value);
ret = (cpps_integer)s->size();
}
else if (type(b) == CPPS_TCLASSVAR)
{
if (b.value.value.domain->domainname == "vector")
{
cpps_vector* v = cpps_converter<cpps_vector*>::apply(b.value);
ret = (cpps_integer)v->size();
}
else if (b.value.value.domain->domainname == "map")
{
cpps_map* v = cpps_converter<cpps_map*>::apply(b.value);
ret = (cpps_integer)v->size();
}
else if (b.value.value.domain->domainname == "set")
{
cpps_set* v = cpps_converter<cpps_set*>::apply(b.value);
ret = (cpps_integer)v->size();
}
}
return ret;
}
object cpps_base_dump(C*c,object o) {
if (type(o) == CPPS_TCLASSVAR)
{
object dump = o["dump"];
if (dump.isfunction()){
return doclassfunction(c, o, dump);
}
}
return nil;
}
void cpps_base_printf_new(C* c, cpps::cpps_value args, ...) {
cpps::object _vct = object(args);
bool isfirst = true;
for (auto& v : cpps::object::vector(_vct)) {
if (!isfirst) cout << ",";
isfirst = false;
cpps_base_printf(c, v.real());
}
}
void cpps_base_printf(C*c,object b)
{
if (type(b) == CPPS_TNUMBER)
{
cpps_number s = object_cast<cpps_number>(b);
cout.precision(20);
cout << s;
}
else if (type(b) == CPPS_TINTEGER)
{
int64 s = object_cast<int64>(b);
cout << s;
}
else if (type(b) == CPPS_TUINTEGER)
{
usint64 s = object_cast<usint64>(b);
cout << s;
}
else if (type(b) == CPPS_TSTRING)
{
std::string s = object_cast<std::string>(b);
cout << s.c_str();
}
else if (type(b) == CPPS_TBOOLEAN)
{
bool bl = object_cast<bool>(b);
cout << (bl ? "true" : "false");
}
else if (type(b) == CPPS_TNIL)
{
cout << "nil";
}
else if (type(b) == CPPS_TCLASSVAR)
{
if (b.getclassname() == "vector")
{
cout << "[";
cpps_vector* v = cpps_converter<cpps_vector*>::apply(b.value);
if (v)
{
bool first = true;
for (v->begin(); v->end(); v->next())
{
if (!first) cout << ",";
first = false;
bool bb = cpps_isstring(v->it());
if(bb) cout << "'";
cpps_base_printf(c,v->it());
if (bb) cout << "'";
}
}
cout << "]";
}
else if (b.getclassname() == "set")
{
cout << "[";
bool first = true;
cpps_set* v = cpps_converter<cpps_set*>::apply(b.value);
if (v)
{
for (v->begin(); v->end(); v->next())
{
if(!first) cout << ",";
first = false;
bool bb = cpps_isstring(v->it());
if (bb) cout << "'";
cpps_base_printf(c, v->it());
if (bb) cout << "'";
}
}
cout << "]";
}
else if (b.getclassname() == "map")
{
cout << "{ ";
cpps_map* v = cpps_converter<cpps_map*>::apply(b.value);
if (v)
{
bool first = true;
for (v->begin(); v->end(); v->next())
{
if (!first) cout << ",";
first = false;
cpps_base_printf(c,v->key());
cout << ": ";
bool bb = cpps_isstring(v->it());
if (bb) { cpps::cpps_console_color(2); cout << "'"; }
else if(cpps_isbasevar(v->it())) { cpps::cpps_console_color(3); }
cpps_base_printf(c,v->it());
if (bb) { cout << "'"; }
cpps::cpps_console_clearcolor();
}
}
cout << " }";
}
else if (b.value.value.domain->domainname == "pair") {
cpps_pair* v = cpps_converter<cpps_pair*>::apply(b.value);
cout << "(";
cpps_base_printf(c, v->first());
cout << ",";
cpps_base_printf(c, v->second());
cout << ")";
}
else
{
object tostring = b["tostring"];
if (tostring.isfunction()) {
cpps_base_printf(c,doclassfunction(c,b, tostring));
}
else {
cpps::cpps_console_color(4);
cout << "class <" << b.value.value.domain->domainname << ">" << endl;
cpps::cpps_console_clearcolor();
cout << "{" << endl;
cpps_debug_trace_domain(c, 4, "", b.value.value.domain);
cout << "}" << endl;
}
}
}
else if (type(b) == CPPS_TTUPLE)
{
cpps_vector* vec = cpps_to_cpps_vector(b.value);
cout << "[";
bool first = true;
for (auto v : vec->realvector())
{
if (!first) cout << ",";
first = false;
cpps_base_printf(c,v);
}
cout << "]";
}
else
{
cout << "not support '" << type_s(b).c_str() << "' type..";
}
}
void cpps_base_endl() {
cout << endl;
}
void cpps_base_printfln_new(C* c, cpps::cpps_value args, ...) {
bool isfirst = true;
cpps::object _vct = object(args);
for (auto& v : cpps::object::vector(_vct)) {
if (!isfirst) cout << ",";
isfirst = false;
cpps_base_printf(c, v.real());
}
cout << endl;
}
void cpps_base_printfln(C* c, object b) {
cpps_base_printf(c,b);
cout << endl;
}
void cpps_base_sleep(cpps_integer msec)
{
#ifdef _WIN32
Sleep((usint32)msec);
#else
usleep((int32)(msec * 1000));
#endif
}
cpps_number cpps_base_tonumber(cpps_value v)
{
return cpps_to_number(v);
}
cpps_integer cpps_base_tointeger(cpps_value v)
{
return cpps_to_integer(v);
}
cpps_uinteger cpps_base_touinteger(cpps_value v)
{
return cpps_to_uinteger(v);
}
std::string cpps_base_tostring(cpps_value v)
{
return cpps_to_string(v);
}
bool cpps_base_isstring(cpps_value v)
{
return cpps_isstring(v);
}
bool cpps_base_isvector(cpps_value v)
{
return cpps_isvector(v);
}
bool cpps_base_isrange(cpps_value v)
{
return cpps_isrange(v);
}
bool cpps_base_ismap(cpps_value v)
{
return cpps_ismap(v);
}
bool cpps_base_ispair(cpps_value v)
{
return cpps_ispair(v);
}
bool cpps_base_isset(cpps_value v)
{
return cpps_isset(v);
}
bool cpps_base_isint(cpps_value v)
{
return cpps_isint(v);
}
bool cpps_base_isuint(cpps_value v)
{
return cpps_isuint(v);
}
bool cpps_base_isbool(cpps_value v)
{
return cpps_isbool(v);
}
bool cpps_base_isnumber(cpps_value v)
{
return cpps_isnumber(v);
}
bool cpps_base_isnull(cpps_value v)
{
return cpps_isnull(v);
}
bool cpps_base_isclassvar(cpps_value v)
{
return cpps_isclassvar(v);
}
bool cpps_base_isclass(cpps_value v)
{
return cpps_isclass(v);
}
bool cpps_base_isellipsis(cpps_value v)
{
return cpps_isellipsis(v);
}
bool cpps_base_istuple(cpps_value v)
{
return v.tt == CPPS_TTUPLE;
}
bool cpps_base_iskindof(cpps_value _cls, cpps_value _var) {
if (!cpps_base_isclass(_cls) || !cpps_base_isclassvar(_var)) return false;
auto cls = cpps_to_cpps_cppsclass(_cls);
auto clsvar = cpps_to_cpps_cppsclassvar(_var);
return clsvar->getcppsclass() == cls;
}
bool cpps_base_isfunction(cpps_value v)
{
return cpps_isfunction(v);
}
cpps_integer cpps_base_objtype(cpps_value v)
{
if (v.tt == CPPS_TLAMBDAFUNCTION) return CPPS_TFUNCTION;
return v.tt;
}
std::string cpps_base_type(cpps_value v) {
std::string ret = "unknow type";
switch (cpps_base_objtype(v))
{
case CPPS_TNIL:
return "nil";
case CPPS_TINTEGER:
return "integer";
case CPPS_TUINTEGER:
return "unsigned integer";
case CPPS_TNUMBER:
return "number";
case CPPS_TBOOLEAN:
return "boolean";
case CPPS_TSTRING:
return "string";
case CPPS_TCLASS:
{
return std::string("class ") + v.value.domain->domainname;
}
case CPPS_TCLASSVAR:
{
return v.value.domain->domainname;
}
case CPPS_TFUNCTION:
return "function";
default:
break;
}
return ret;
}
int32 cpps_base_system(std::string v)
{
return system(v.c_str());
}
void cpps_base_setconsoletitle(std::string title)
{
#ifdef _WIN32
SetConsoleTitleA(title.c_str());
#endif
}
std::string cpps_module_path(std::string libname) {
std::string path = "lib/" + libname + "/";
std::string fpath;
#ifdef _WIN32
fpath = cpps_rebuild_filepath(path + (libname + ".dll"));
if (!fpath.empty())
{
return cpps_io_getfilepath(fpath);
}
#else
#if defined LINUX
fpath = cpps_rebuild_filepath(path + "lib" + (libname + ".so"));
#elif defined __APPLE__
fpath = cpps_rebuild_filepath(path + "lib" + (libname + ".dylib"));
#endif
if (!fpath.empty())
{
return cpps_io_getfilepath(fpath);
}
#endif
fpath = cpps_rebuild_filepath(path + "main.cpp");
if (!fpath.empty())
{
return cpps_io_getfilepath(fpath);
}
return "";
}
bool cpps_checklibrary(std::string libname) {
std::string path = "lib/" + libname + "/";
std::string fpath;
#ifdef _WIN32
fpath = cpps_rebuild_filepath(path + (libname + ".dll"));
if (!fpath.empty())
{
return true;
}
#else
#if defined LINUX
fpath = cpps_rebuild_filepath(path + "lib" + (libname + ".so"));
#elif defined __APPLE__
fpath = cpps_rebuild_filepath(path + "lib" + (libname + ".dylib"));
#endif
if (!fpath.empty())
{
return true;
}
#endif
fpath = cpps_rebuild_filepath(path + "main.cpp");
if (!fpath.empty())
{
return true;
}
return false;
}
bool cpps_loadlibrary(C *c,std::string libname, cppsbuffer& buffer)
{
std::string path = "lib/"+ libname + "/";
std::string fpath;
bool bexits = false;
if (c->modulelist.find(libname) != c->modulelist.end()) return true;
bool sv = false;
#ifdef _WIN32
fpath = cpps_rebuild_filepath(path + (libname + ".dll"));
if (!fpath.empty())
{
HMODULE module = ::LoadLibraryA(fpath.c_str());
std::string libfuncname = "cpps_attach";
if (module == NULL)
{
printf("Load module [%s] : %d faild.\r\n", libname.c_str(),GetLastError());
FreeLibrary(module);
return false;
}
cpps_attach_func cpps_attach = (cpps_attach_func)GetProcAddress(module, libfuncname.c_str());
if (cpps_attach == NULL)
{
FreeLibrary(module);
printf("Load module [%s] faild\r\n", libname.c_str());
return false;
}
c->modulelist.insert(phmap::flat_hash_map<std::string, HMODULE>::value_type(libname, module));
sv = true;
cpps_attach(c);
bexits = true;
}
#else
#if defined LINUX
fpath = cpps_rebuild_filepath(path + "lib" + (libname + ".so"));
#elif defined __APPLE__
fpath = cpps_rebuild_filepath(path + "lib" + (libname + ".dylib"));
#endif
if (!fpath.empty())
{
HMODULE mod = dlopen(fpath.c_str(), RTLD_LAZY);
if (mod == NULL)
{
printf("dlopen [%s]:%s faild\r\n", libname.c_str(), dlerror());
return false;
}
dlerror();
CPPS_ST_API* api = (CPPS_ST_API*)dlsym(mod, "LIBAPI");
if (api == NULL)
{
dlclose(mod);
printf("dlsym [LIBAPI] faild\r\n");
return false;
}
c->modulelist.insert(phmap::flat_hash_map<std::string, HMODULE>::value_type(libname, mod));
sv = true;
api->cpps_attach(c);
bexits = true;
}
#endif
fpath = cpps_rebuild_filepath(path + "main.cpp");
if (!fpath.empty())
{
bexits = true;
if(!sv)
c->modulelist.insert(phmap::flat_hash_map<std::string, HMODULE>::value_type(libname, NULL));
std::string fileSrc;
cpps_load_filebuffer(fpath.c_str(), fileSrc);
buffer.append(fpath, fileSrc.c_str(), (int32)fileSrc.size());
/*node* o = loadbuffer(c,c->_G, fileSrc, fpath);
cpps_stack* stack = c->stack_alloc();
stack->init("main.cpp", 0, "import");
c->push_stack(stack);
cpps_step_all(c, CPPS_MUNITRET, c->_G,c->_G, o);
c->pop_stack();
cpps_gc_check_step(c);
c->stack_free(stack);
if (o) { cpps_destory_node(o); CPPSDELETE(o); o = NULL; }*/
}
if (!bexits)
throw cpps_error(c->curnode->filename, c->curnode->line, cpps_error_normalerror, "No Found %s module", libname.c_str());
return true;
}
void cpps_detach_library(HMODULE module,const std::string& libname, C* c)
{
//printf("cpps_detach_library -> %s\r\n", libname.c_str());
if (module == NULL) return;
#ifdef _WIN32
std::string libfuncname = "cpps_detach";
cpps_detach_func cpps_detach = (cpps_detach_func)GetProcAddress(module, libfuncname.c_str());
if (cpps_detach == NULL)
{
printf("Free Module %s faild.\r\n", libname.c_str());
}
else
{
cpps_detach(c);
FreeLibrary(module);
}
#else
dlerror();
CPPS_ST_API* api = (CPPS_ST_API*)dlsym(module, "LIBAPI");
if (api == NULL)
{
printf("dlsym [LIBAPI] %s faild\r\n", libname.c_str());
}
else
{
api->cpps_detach(c);
#if defined LINUX
dlclose(module);
#endif
}
#endif
}
bool cpps_freelibrary(C* c, std::string libname)
{
if (c->modulelist.find(libname) == c->modulelist.end()) return true;
#ifdef _WIN32
bool ret = false;
phmap::flat_hash_map<std::string, HMODULE>::iterator it = c->modulelist.find(libname);
if (it != c->modulelist.end())
{
HMODULE module = it->second;
if (module) {
cpps_detach_library(module, libname, c);
}
c->modulelist.erase(it);
ret = true;
}
return ret;
#else
bool ret = false;
phmap::flat_hash_map<std::string, HMODULE>::iterator it = c->modulelist.find(libname);
if (it != c->modulelist.end())
{
HMODULE module = it->second;
if (module) {
cpps_detach_library(module, libname, c);
}
c->modulelist.erase(it);
ret = true;
}
return ret;
#endif
}
cpps_value cpps_getargs(C* c)
{
cpps_vector* vct;
cpps_value ret;
newclass<cpps_vector>(c, &vct, &ret);
for (int i = 0; i < c->application_argc; i++)
{
vct->push_back(cpps_value(c, c->application_argv[i]));
}
return ret;
}
#if defined _WIN32
std::string cpps_base_win_execmd(std::string pszCmd)
{
// ���������ܵ�
SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };
HANDLE hRead, hWrite;
if (!CreatePipe(&hRead, &hWrite, &sa, 0))
{
return "";
}
// ���������н���������Ϣ(�����ط�ʽ���������λ�������hWrite
STARTUPINFO si = { sizeof(STARTUPINFO) };
GetStartupInfo(&si);
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
si.wShowWindow = SW_HIDE;
si.hStdError = hWrite;
si.hStdOutput = hWrite;
// ����������
PROCESS_INFORMATION pi;
if (!CreateProcessA(NULL, (LPSTR)pszCmd.c_str(), NULL, NULL, TRUE, NULL, NULL, NULL, &si, &pi))
{
return "";
}
// �����ر�hWrite
CloseHandle(hWrite);
// ��ȡ�����з���ֵ
std::string strRetTmp;
char buff[4096] = { 0 };
DWORD dwRead = 0;
strRetTmp = buff;
while (memset(buff, 0, sizeof(buff)),ReadFile(hRead, buff, 4095, &dwRead, NULL))
{
strRetTmp += buff;
}
CloseHandle(hRead);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return strRetTmp;
}
#endif
std::string cpps_base_execmd(C* c, std::string cmd)
{
#if defined _WIN32
return cpps_base_win_execmd(cmd);
#else
FILE *fp = popen(cmd.c_str(), "r");
if (!fp) {
return "";
}
std::string strRetTmp;
char buf[1024] = { 0 };
while (memset(buf, 0, sizeof(buf)), fgets(buf, sizeof(buf) - 1, fp) != 0) {
strRetTmp += buf;
}
pclose(fp);
return strRetTmp;
#endif
}
void cpps_base_environ_set(std::string k,::string v)
{
#if defined _WIN32
std::string setv = k + "=" + v;
_putenv(setv.c_str());
#else
setenv(k.c_str(), v.c_str(), 1);
#endif
}
std::string cpps_base_environ_get(std::string k)
{
char* pathvar;
pathvar = getenv(k.c_str());
if (!pathvar) return "";
return pathvar;
}
cpps_value cpps_base_serializer_encode(C*c,cpps_value v,cpps_value tp)
{
if (v.tt != CPPS_TCLASSVAR) return nil;
cpps_integer serializer_type = 1;//1. serializer.vector 2.serializer.map
if (cpps_isint(tp)) serializer_type = tp.value.integer;
cpps_cppsclassvar* classvar = (cpps_cppsclassvar*)v.value.domain;
cpps_value ret;
if (serializer_type == 1 && classvar->stacklist) {
cpps_vector* vct;
newclass<cpps_vector>(c, &vct,&ret);
for (auto var : *classvar->stacklist)
vct->push_back(var->getval());
}
else if(serializer_type == 2){
cpps_map* m;
newclass<cpps_map>(c, &m,&ret);
for (auto var : classvar->varList)
m->insert(cpps_value(c,var.first),var.second->getval());
}
return ret;
}
cpps_value cpps_base_serializer_decode(C* c, cpps_value cls, cpps_value v)
{
cpps_value ret;
if (cls.tt != CPPS_TCLASS) return nil;
cpps_cppsclass* cppsclass = (cpps_cppsclass*)cls.value.domain;
if (cpps_base_isvector(v)) {
cpps_vector* vct = cpps_to_cpps_vector(v);
cpps_value v2;
newcppsclasvar(c, cppsclass,&v2);
if (v2.value.domain->stacklist && vct->realvector().size() == v2.value.domain->stacklist->size())
{
size_t size = (size_t)vct->size();
for (size_t i = 0; i < size; i++) {
cpps_regvar* regv = (*(v2.value.domain->stacklist))[i];
regv->setval(vct->realvector()[i]);
}
ret = v2;
}
}
else if(cpps_base_ismap(v)){
cpps_map* m = cpps_to_cpps_map(v);
cpps_value v2;
newcppsclasvar(c, cppsclass,&v2);
//if (m->realmap().size() == v2.value.domain->stacklist->size())
{
for (auto it : m->realmap()) {
cpps_domain* leftdomain = NULL;
cpps_regvar * regv = v2.value.domain->getvar(cpps_to_string(it.first), leftdomain, false);
if (regv)
{
regv->setval(it.second);
}
}
ret = v2;
}
}
return ret;
}
size_t partition(cpps_std_vector& v, size_t begin, size_t end)
{
cpps_value pivot = v[begin];
size_t left = begin + 1;
size_t right = end;
while (true)
{
while (left < right && v[right] >= pivot)
right--;
while (left < right && v[left] < pivot)
left++;
if (left == right)
break;
std::swap(v[left], v[right]);
}
if (v[left] >= pivot)
return begin;
v[begin] = v[left];
v[left] = pivot;
return left;
}
void quickSort(cpps_std_vector& v, size_t begin, size_t end)
{
if (begin >= end)
return;
size_t boundary = partition(v, begin, end);
quickSort(v, begin, boundary - 1);
quickSort(v, boundary + 1, end);
}
void cpps_base_sort(object v)
{
if (v.isvector()) {
cpps_vector* vec = cpps_to_cpps_vector(v.value);
quickSort(vec->realvector(), 0,size_t( vec->size() - 1));
}
}
void cpps_base_real_shuffle(cpps_std_vector& vec)
{
size_t n = vec.size();
if (n <= 0)
return;
for (size_t i = 0; i < n; i++)
{
//��֤ÿ�ε�iλ��ֵ�����漰����iλ��ǰ
size_t index = i + ((size_t)cpps_math_rand()) % (n - i);
std::swap(vec[index], vec[i]);
}
}
void cpps_base_shuffle(object v)
{
if (v.isvector()) {
cpps_vector* vec = cpps_to_cpps_vector(v.value);
cpps_base_real_shuffle(vec->realvector());
}
}
void cpps_base_reverse(object v)
{
if (v.isvector()) {
cpps_vector* vec = cpps_to_cpps_vector(v.value);
reverse(vec->realvector().begin(),vec->realvector().end());
}
}
void cpps_base_exit(cpps_integer exitcode)
{
exit((int)exitcode);
}
void cpps_setechofunc(C*c,object echofunc,object echoleft)
{
cpps::object::define(c, "__echofunc", echofunc);
cpps::object::define(c, "__echoleft", echoleft);
}
cpps_value cpps_base_parse(C* c, cpps_value buffer) {
if (!cpps_isstring(buffer)) return nil;
std::string* str = cpps_get_string(buffer);
bool _buildoffset = c->buildoffset;
c->buildoffset = false;
node* o = loadbuffer(c, c->_G, *str, c->curnode->filename);
c->buildoffset = _buildoffset;
node *copynode = NULL;
cpps_value ret;
newclass(c, &copynode, &ret);
copynode->clone(o);
cpps_destory_node(o); o->release(); o = NULL;
return ret;
}
std::string base_BinToHex(std::string strBin)
{
std::string strHex;
size_t len = strBin.size();
strHex.resize(strBin.size() * 2);
for (size_t i = 0; i < len; i++)
{
uint8_t cTemp = strBin[i];
for (size_t j = 0; j < 2; j++)
{
uint8_t cCur = (cTemp & 0x0f);
if (cCur < 10)
{
cCur += '0';
}
else
{
cCur += (('a') - 10);
}
strHex[2 * i + 1 - j] = cCur;
cTemp >>= 4;
}
}
return strHex;
}
std::string base_HexToBin(std::string strHex)
{
if (strHex.size() % 2 != 0)
{
return "";
}
std::string strBin;
strBin.resize(strHex.size() / 2);
for (size_t i = 0; i < strBin.size(); i++)
{
uint8_t cTemp = 0;
for (size_t j = 0; j < 2; j++)
{
char cCur = strHex[2 * i + j];
if (cCur >= '0' && cCur <= '9')
{
cTemp = (cTemp << 4) + (cCur - '0');
}
else if (cCur >= 'a' && cCur <= 'f')
{
cTemp = (cTemp << 4) + (cCur - 'a' + 10);
}
else if (cCur >= 'A' && cCur <= 'F')
{
cTemp = (cTemp << 4) + (cCur - 'A' + 10);
}
else
{
return "";
}
}
strBin[i] = cTemp;
}
return strBin;
}
void cpps_regbase(C *c)
{
cpps::_module(c)[
_class<C>("C_STATE"),
_class<node>("cpps_node")
.def("release",&node::cpps_release),
def_inside("parse", cpps_base_parse),
def("printf", cpps_base_printf_new),
def("print", cpps_base_printf_new),
def("printfln", cpps_base_printfln_new),
def("println", cpps_base_printfln_new),
//def_inside("endl", cpps_base_endl),
def_inside("dump", cpps_base_dump),
def("exit", cpps_base_exit),
def("sleep", cpps_base_sleep),
def("Sleep", cpps_base_sleep),
def("usleep", cpps_base_sleep),
def("hex2bin", base_HexToBin),
def("bin2hex", base_BinToHex),
def("tonumber", cpps_base_tonumber),
def("double", cpps_base_tonumber),
def("toint", cpps_base_tointeger),
def("touint", cpps_base_touinteger),
def("int", cpps_base_tointeger),
def("uint", cpps_base_touinteger),
def("tostring", cpps_base_tostring),
def("str", cpps_base_tostring),
def("isstring", cpps_base_isstring),
def("isint", cpps_base_isint),
def("isuint", cpps_base_isuint),
def("isbool", cpps_base_isbool),
def("isvector", cpps_base_isvector),
def("isrange", cpps_base_isrange),
def("ismap", cpps_base_ismap),
def("isnull", cpps_base_isnull),
def("isnumber", cpps_base_isnumber),
def("isfunction", cpps_base_isfunction),
def("isclassvar", cpps_base_isclassvar),
def("isclass", cpps_base_isclass),
def("isellipsis", cpps_base_isellipsis),
def("istuple", cpps_base_istuple),
def("iskindof", cpps_base_iskindof),
def("objtype", cpps_base_objtype),
def("type", cpps_base_type),
def("system", cpps_base_system),
def("len", cpps_base_len),
def("sort", cpps_base_sort),
def("shuffle", cpps_base_shuffle),
def("reverse", cpps_base_reverse),
def("isvalid", cpps_base_isvalid),
def("isdebug", cpps_base_isdebug),
def("SetConsoleTitle", cpps_base_setconsoletitle),
def("abort", abort),
def_inside("setechofunc", cpps_setechofunc),
defvar(c,"_VERSION", CPPS_VER),
defvar(c,"_VERSIONNO", CPPS_VERN),
def("check_module", cpps_checklibrary),
def("module_path", cpps_module_path),
//def_inside("loadlibrary", cpps_loadlibrary),
//def_inside("freelibrary", cpps_freelibrary),
def_inside("getargs", cpps_getargs),
def_inside("execmd",cpps_base_execmd)
];
cpps::_module(c, "ot")[
defvar(c,"int", CPPS_TINTEGER),
defvar(c,"uint", CPPS_TUINTEGER),
defvar(c,"bool", CPPS_TBOOLEAN),
defvar(c,"string", CPPS_TSTRING),
defvar(c,"classvar", CPPS_TCLASSVAR),
defvar(c,"function", CPPS_TFUNCTION),
defvar(c,"domain", CPPS_TDOMAIN),
defvar(c,"ptr", CPPS_TREF),
defvar(c,"number", CPPS_TNUMBER),
defvar(c,"nil", CPPS_TNIL),
defvar(c,"lambda", CPPS_TLAMBDAFUNCTION)
];
cpps::_module(c, "environ")[
def("get",cpps_base_environ_get),
def("set",cpps_base_environ_set)
];
cpps::_module(c, "serializer")[
def_inside("encode",cpps_base_serializer_encode),
def_inside("decode",cpps_base_serializer_decode),
defvar(c,"vector",1),
defvar(c,"map",2)
];
cpps::_module(c, "sys")[
defvar(c, "platform", CPPS_CURRENT_PLANTFORM),
defvar(c, "easyplatform", CPPS_CURRENT_EASYPLANTFORM),
defvar(c, "os", CPPS_CURRENT_EASYPLANTFORM),
defvar(c, "arch", CPPS_CURRENT_ARCH),
defvar(c, "builder_version", CPPS_BUILDER_VERSION),
defvar(c, "version", CPPS_VER),
defvar(c, "versionno", CPPS_VERN),
#ifdef _DEBUG
defvar(c, "debug", true)
#else
defvar(c, "debug", false)
#endif
];
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

CPPS是一种轻量级的嵌入式脚本语言,其语法类似于C++。它具有当前主流语言的许多特性,包括协程、面向对象、lambda、闭包、泛型变量、自定义模块支持、GC垃圾收集和跨平台。CPPS将程序解释为字节码,通过内置语法解析在虚拟机中运行
取消

发行版 (3)

全部

开源评估指数源自 OSS-Compass 评估体系,评估体系围绕以下三个维度对项目展开评估:

1. 开源生态

  • 生产力:来评估开源项目输出软件制品和开源价值的能力。
  • 创新力:用于评估开源软件及其生态系统的多样化程度。
  • 稳健性:用于评估开源项目面对多变的发展环境,抵御内外干扰并自我恢复的能力。

2. 协作、人、软件

  • 协作:代表了开源开发行为中协作的程度和深度。
  • 人:观察开源项目核心人员在开源项目中的影响力,并通过第三方视角考察用户和开发者对开源项目的评价。
  • 软件:从开源项目对外输出的制品评估其价值最终落脚点。也是开源评估最"古老"的主流方向之一"开源软件" 的具体表现。

3. 评估模型

    基于"开源生态"与"协作、人、软件"的维度,找到与该目标直接或间接相关的可量化指标,对开源项目健康与生态进行量化评估,最终形成开源评估指数。

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/cppscript/cpps.git
git@gitee.com:cppscript/cpps.git
cppscript
cpps
cpps
v1.0.2
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /