龙空技术网

国产编程语言 CBrother 小巧 精简 易开发 快速 多线程

我爱吃西瓜2023 7423

前言:

眼前你们对“易语言转c语言工具”可能比较珍视,你们都想要剖析一些“易语言转c语言工具”的相关资讯。那么小编同时在网上汇集了一些对于“易语言转c语言工具””的相关资讯,希望大家能喜欢,各位老铁们一起来学习一下吧!

CBrother是一门跨平台的脚本语言,支持真正的多线程,它抛弃了传统脚本语言的GIL全局锁技术,从而更能发挥多核CPU的强劲性能。

CBrother语法继承了C类语法体系,有Java,C++,C#,JS,PHP等语言基础便可以直接上手编写代码。

你可以用C++扩展它,也可以将CBrother嵌入C++语言里使用。

Cbrother官网:

让编程变得更简单创建一个 helloworld.cb 代码:

function main(parm){    print "Hello World!";} 
创建小型HttpServer服务器:
import CBHttp.codefunction main(parm){    var httpServer = new HttpServer();    httpServer.startServer();	    while(1)  //主线程不能退出    {        Sleep(1000);    }}
MySQL用法
import CBMySQL.codefunction main(parm){	var mysql = new MySQL("127.0.0.1",3306,"root","root","test");	if(!mysql.connect())	{		print "mysql connect err!!";		return;	}		var res = mysql.upDate("INSERT INTO test (`strv`, `intv`) VALUES ('333', 222)");	if(!res)	{		print "update err " + mysql.getErr();	}			res = mysql.upDate("INSERT INTO test (`strv`, `intv`) VALUES ('555', 666)");	if(!res)	{		print "update err " + mysql.getErr();	}				var res = mysql.query("select * from test");	if(!res)	{		print "query err " + mysql.getErr();		return;	}		while(mysql.next())	{		var strv = mysql.getString(0);		var intv = mysql.getInt(1);				print "mysql data: " + strv + " " + intv;				var strv1 = mysql.getString("strv");		var intv = mysql.getInt("intv");				print "name query mysql data: " + strv + " " + intv;	}				mysql.closeConnect();}
Socket通信

服务端:

import CBSocket.codeclass TcpAction{	var tcpModule;	function OnAccept(sock)	{			print "accept " + sock;	}		function OnClose(sock)	{		print "onclose " + sock;	}		function OnRecv(sock,byteArray,len)	{		print "onrecv " + sock + " " + byteArray.readString() + " len:" + len;				var byteArray = new ByteArray();		byteArray.writeString("hello tcp client");		tcpModule.sendData(sock,byteArray);	}		function OnSend(sock,len)	{		print "onsend " + sock + " " + len;	}}function main(parm){	var tcpModule = new TcpModule();	var tcpAction = new TcpAction();	tcpAction.tcpModule = tcpModule;	tcpModule.setTcpAction(tcpAction);	//设置TCP处理类	tcpModule.addListenPort(6060);	//监听6060端口	tcpModule.addListenPort(6061,"*");	//监听6061端口,IPV4和IPV6兼容	tcpModule.start();		while(1)				//主线程不能退出	{		Sleep(1000);	}}

客户端:

import CBSocket.codeclass TcpAction{	var tcpModule;	function OnClose(sock)	{		print "onclose " + sock;	}		function OnRecv(sock,byteArray,len)	{		print "onrecv " + sock + " " + byteArray.readString() + " len:" + len;	}		function OnSend(sock,len)	{		print "onsend " + sock + " " + len;	}		function OnConnect(sock)	{		print "onconnect " + sock;				var byteArray = new ByteArray();		byteArray.writeString("hellp tcp server!");		tcpModule.sendData(sock,byteArray);	}}function main(parm){	var tcpModule = new TcpModule();	var tcpAction = new TcpAction();	tcpAction.tcpModule = tcpModule;	tcpModule.setTcpAction(tcpAction);	//设置TCP处理类	tcpModule.start();		tcpModule.connect("127.0.0.1",6060);		while(1)				//主线程不能退出	{		Sleep(1000);	}}
用CLib来加载一个第三方动态库
function loadLib(){	var systemName = SystemName();	var libPath = GetRoot();	if(systemName == "windows")	{		libPath += "testdll.dll";	}	else if(systemName == "linux")	{		libPath += "libtestdll.so";	}	else	{		libPath += "libtestdll.dylib";	}		var clibs = new CLib(libPath);	if(!clibs.load())	{		print "load err!";		return 0;	}		print "load success!!";}

调用C++ 代码

C++:

//c++函数定义int tAdd(int a,int b){	return a + b;}

CB代码:

mport CBCLib.codefunction main(parm){	var clibs = loadLib();	var tAdd = clibs.findFunc("tAdd","int","int","int");	var res = tAdd.callFunc(100,300);	print "tAdd : " + res;}
基本类型
var v1 = 100;	//整型var v2 = 100.0;	//浮点型var v3 = "100"; //字符串var v4 = true; //or false   布尔值var v5 = null; //空对象 var v6;	//空对象var v7 = UINT(100); //无符号整型var v8 = 0x00ff00aa;	//整型 0x开头为16进制赋值var v9 = 0o11537;	//整型 0o开头为8进制赋值var v10 = 0b10101;	//整型 0b开头为2进制赋值var v11 = new Array();	//数组var v12 = new Map();	//字典var v13 = new List();	//列表class MyClass{    var a = 100;    var b = "100";}var v14 = new MyClass();	//自定义类型var v15 = 0xffffffffffff0000;	//数值超过int范围时,自动变为longvar v16 = 4200000000;		//数值超过int范围时,自动变为longvar v17 = 'a';			//整型 a的ascii值97

标签: #易语言转c语言工具