import glob,re
for f in glob.glob("*.lua"):
fout = file("%s.out"%f[:-4],"w+")
for line in file(f):
if re.match(r"^\s*$", line):
fout.write(line)
continue
if re.match(r"^\s*--", line):
fout.write("//"+line)
continue
line=line.rstrip()
line=re.sub(r"\bif\b", 'if (', line)
line=re.sub(r"\bthen\b", ' ) {', line)
line=re.sub(r"\bend\b", '}', line)
line=re.sub(r"\belse\b", '} else {', line)
line=re.sub(r"\belseif\b", '} else if (', line)
if re.match(r".*\{.*\}", line):
line=re.sub(r"\}", '; }', line)
if not re.match(r".*[{}]$", line):
line+=";"
fout.write(line+"\n")
很不完善,仅支持单个函数体内转换,临时变量声明没有处理
lua源码到c的简单转换
最新推荐文章于 2023-06-06 23:41:18 发布