cppsscript欢迎CPPS是一个功能强大,运行速度快,容易上手的解释型脚本语言,非常容易学习和使用,并且可以很容易的嵌入到C++项目中。CPPS被设计的初衷是让那些和作者一样不喜欢LUA,PY,等等脚本语法的开发者使用,它可以对接各种项目,无论游戏,WEB,或者是人工智能方面。它的语法极为像C++,所以C++开发者可以很快速的上手,无需太深入的学习它。招募协同软件作者,三方模块作者.下载与编译CPPS的下载与安装非常简单,CPPS不依赖于任何第三方库,仅仅下载就可以编译。LINUX&MACOS:gitclonehttps://github.com/johnsonyl/cpps.gitcmake.makemakeinstall;根据需要是否编译扩展模块.cppsbuildlibsWindowsgitclonehttps://github.com/johnsonyl/cpps.gitcmake.使用VisualStudio打开libcpps.sln进行编译即可。cdlibs;根据需要是否编译扩展模块.cmake.使用VisualStudio打开cppslibs.sln进行编译即可。是不是非常简单?libs文件夹是内部扩展模块.具体编译规则请查看文档脚本文档在https://docs.cppscript.orgExample:HelloWorld:println("helloworld");base64:#import"base64"vars="abc";println("source:{s}");varencode_s=base64.encode(s);println("encode_s:{encode_s}");vardeocde_s=base64.decode(encode_s);println("deocde_s:{deocde_s}");asyncio:asyncvartest(){println("dotestfunction");awaitasyncio.wait_for(asyncio.sleep(2000),100);println("dotestfunctiondone");return"test";}asyncvartest1(){println("dotest1function");awaitasyncio.sleep(1000);println("dotest1functiondone");return"test1";}vartest_call_back(vartask,varcontext){println(task.get_name());println(context);}asyncvarmain(){vartask1=asyncio.create_task(test());task1.set_name("Customnamesareusedtodistinguish");task1.add_done_callback(test_call_back,"Customcontextcontent");vartask2=asyncio.create_task(test1());varret=awaitasyncio.wait(task1);if(ret.timeout()){println("task1wastimeouted.");}println("state:{ret.state()}");println(ret.result());try{println(awaittask2);}catch(vare){println("oh,wecatchsomeerror");println("{e.what()}line:{e.line()}file:{e.file()}");println(e.callstack());}println("finish");}asyncio.run(main());socket-server:system("chcp65001");//useutf8string#import"socket"//servervarsocket_accept(varsocketIndex){println("acceptd:{socketIndex}");}varsocket_data(varsocketIndex,varbuffer){varpackageSize=buffer.readInt32();vars=buffer.readString(packageSize-4);println(s);if(s=="e"){srv.closesocket(socketIndex);}varwriter=newBuffer();writer.writeString(s);socket_send(socketIndex,writer);}varsocket_close(varsocketIndex,varerr,varerrstr){println("closed:{socketIndex},err:{err},errstr:{errstr}");}varsocket_parser(varheaderbuffer){varsize=headerbuffer.readInt32();returnsize;}varsocket_send(varsocketIndex,varbuffer){varwriter=newBuffer();writer.writeInt32(buffer.length()+4);writer.write(buffer,buffer.length());srv.send(socketIndex,writer);}println("startserver");varsrv=newsocket::server().setoption(newServerOption(){ip="0.0.0.0",headersize=4,//header4bytesaccept=socket_accept,data=socket_data,close=socket_close,parser=socket_parser}).listen(4060);println("startover");while(true){srv.run();Sleep(1);}client:system("chcp65001");//useutf8string#import"socket"//clientvarsocket_connected(){println("connected");varwriter=newBuffer();writer.writeString("thisisapingpongmsg");socket_send(writer);}varsocket_data(varbuffer){varpackageSize=buffer.readInt32();vars=buffer.readString(packageSize-4);println(s);Sleep(100);varwriter=newBuffer();writer.writeString(s);socket_send(writer);}varsocket_close(varerr,varerrstr){println("closed:err:{err},errstr:{errstr}");}varsocket_parser(varheaderbuffer){varsize=headerbuffer.readInt32();returnsize;}varsocket_send(varbuffer){varwriter=newBuffer();varsize=buffer.length();writer.writeInt32(size+4);writer.write(buffer,buffer.length());client.send(writer);}varclient=newsocket::client();client.setoption(newClientOption(){connected=socket_connected,data=socket_data,close=socket_closeheadersize=4,//header4bytesparser=socket_parser});varb=client.connect("127.0.0.1",4060);while(true){client.run();Sleep(1);}httprequest:system("chcp65001");//useutf8string#import"http"varrequest=newhttp::httprequest();request.setcookiefile("cookies.txt");//request.setproxy(httpproxy.SOCK5,"192.168.1.166:25455");//request.setproxyaccount("johnsonyl","mima");request.addheaders({User-Agent:"cppsrequest/1.1.0"});varret=request.get("https://127.0.0.1:8080/Home/test?kkk=100");println("-------------------GET-------------------------");println("get:{ret}");varcookies=request.getcookies();println("cookies:{cookies}");varheaders=request.getheaders();println("headers:{headers}");println("-------------------POST-------------------------");ret=request.post("https://127.0.0.1:8080/Home/test","kkk=100");println("post:{ret}");varcookies=request.getcookies();println("cookies:{cookies}");varheaders=request.getheaders();println("headers:{headers}");println("-------------------END-------------------------");声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态
评论