def ChangeDict2LuaData(data, title, dataName):  #专门转换Dict开头的函数的数据
    exec(data)
    data = slpp.SLPP().encode(eval(dataName))
    data = "\n--%s\n" % (
        str(title)
    ) + "return " + data + "\n"  #+ ChangeTitleDictData2Class(dataName,title)
    LuaMakeRequirHead(dataName)
    return data
def GetEvalStr(tems, changelua=False):  #Make More File的时候需要Change
    if isinstance(tems, float): tems = int(tems)
    tems = str(tems)
    if tems and tems[0] not in ['[', '(', '{']:
        tems = "[" + tems + ']'
    tems = eval(tems)
    if changelua:
        if tems:
            tems = slpp.SLPP().encode(tems)
        else:
            tems = {}
    return str(tems)
def Change2LuaData(data,title,dataName):#专门转换Map开头的函数的数据
    exec data;
    data = slpp.SLPP().encode(eval(dataName));
    data = "\n--%s\n" % (str(title)) + "return "  + data + "\n" #+ ChangeTitleData2Class(dataName,title) 
    LuaMakeRequirHead(dataName);
    return data;
Example #4
0
def main(dir):
	startbaseid = 256+1;
	startid = 256;
	maxid = 65535;
	dc = {}
	dcids = {}
	if exists("protoidjs.json"):
		f = open("protoidjs.json","r+")
		buf = f.read()
		f.close()
		dcs = json.loads(buf)
		dc = dcs["name"]
		if dc:
			for k,v in dc.items():
				dcids[v] = k
				if v > startid : 
					startid = v 
				

	re_message = re.compile("message\s\w+")
	re_pack = re.compile("(package)(\s\w+)")
	ls2 = []
	bok = True
	newdc = {}
	newids = {}
	for filename in os.listdir(dir):
		filetype = filename[-6:]
		if filetype == ".proto":
			f = open(dir + filename)
			buf = f.read()
			f.close()
			ls = re_pack.findall(buf)
			protoname = ""
			if len(ls) > 0 :
				protoname = ls[0][1].strip() + "."
			ls = re_message.findall(buf)
			#
			for s in ls :
				name = s.replace("message", "").strip()
				if not name[0:3] in ["C2S","S2C","c2s","s2c"] :
					continue
				s2 = protoname + name # s.strip("message").strip() 
				if s2 in dc:
					newdc[s2] = dc[s2]
					newids[dc[s2]] = s2
					ls2.append(s2)
					#print("Warring:\n\t注意有协议重复了",s2)
				else:
					startid = startid + 1
					temid = startid
					for i in range(maxid - startbaseid):
						key = i + startbaseid
						if  key not in  dcids and  key not in newids : 
							temid = key 
							break;
					if startid >= maxid : print("warring:\n\t注意已超过了最大2字节的ID了")
					newdc[s2] = temid
					newids[temid] = s2
					ls2.append(s2)
					bok = True
	if bok: #有数据更新
		#write json
		savedc = {"name":newdc,"idnames":newids}
		tem = json.dumps(savedc,indent=True)
		f = open("protoidjs.json", "w")
		f.write(tem)
		f.close()
		#write lua
		tem ="return " + slpp.SLPP().encode(savedc,[","])
		f = open("protoids.lua", "w")
		f.write(tem)
		f.close()
		#out cs
		printCs(newdc)