Forum

> > Off Topic > Lua Formatter
Forums overviewOff Topic overviewLog in to reply

English Lua Formatter

9 replies
To the start Previous 1 Next To the start

old Re: Lua Formatter

memo
COMMUNITY BANNED Off Offline

Quote
You mean if i put a lua have a error, it fix that error Automatically ?

old Re: Lua Formatter

memo
COMMUNITY BANNED Off Offline

Quote
Heavy has written
No. It just makes your code more readable and better looking. Good idea anyways


Oh i see , i use it on a test script , yea its make the script more readable and good looking thanks Leegao for this is a AWESOME idea .

old Re: Lua Formatter

Lee
Moderator Off Offline

Quote
Directly from the source code

1
2
3
4
5
6
7
8
function gg.relevel() gg.pmin = gg.maxlvl;gg.pmax = gg.minlvl;local n = 0   ;
local x = 0    ;
for k, v in pairs(gg.players) do;local lvl = v.level              ;
if lvl < gg.pmin and lvl > gg.minlvl then gg.pmin = lvl end    ;
if lvl > gg.pmax and lvl <= gg.maxlvl then gg.pmax = lvl end;if lvl >= gg.minlvl then     ;
n = n+1       ;x = x+lvl       ;end;
end ;gg.pavg = math.floor(x/n);
end

=>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function gg.relevel()
	gg.pmin = gg.maxlvl
	gg.pmax = gg.minlvl
	local n = 0
	local x = 0
	for k, v in pairs(gg.players) do
		local lvl = v.level
		if lvl < gg.pmin and lvl > gg.minlvl then
			gg.pmin = lvl
		end
		if lvl > gg.pmax and lvl <= gg.maxlvl then
			gg.pmax = lvl
		end
		if lvl >= gg.minlvl then
			n = n+1
			x = x+lvl
		end
	end
	gg.pavg = math.floor(x/n)
end

Although there are a few test cases of assignment functions embeded within tables that haven't been implemented via the regex parser yet.

old Re: Lua Formatter

Flacko
User Off Offline

Quote
Really nice, I wished I knew python to edit yours to make a C++ one

old Re: Lua Formatter

YellowBanana
BANNED Off Offline

Quote
1
2
3
4
5
a    = 5
b =    6
if(a > b) then
print("hello")
end

--->

1
2
3
4
5
1 a    = 5
2 b =    6
3 if(a > b) then
4 print("hello")
5 end

Not really nicer

u should check for parentheses..
because without parenteses it does work.

old Re: Lua Formatter

Flacko
User Off Offline

Quote
@Banana: You should press the "view source" button if you want to copy it without the line numbers.

old Re: Lua Formatter

Lee
Moderator Off Offline

Quote
it's not the parenthesis, the initial regex expression was

r"if .+ then"

Which doesn't match if(.+then as there are no spaces after if. It's fixed now.
To the start Previous 1 Next To the start
Log in to replyOff Topic overviewForums overview