gmod_src: Added continue keyword to Lua

Revision 649
Added continue keyword to Lua Changed Files:
[li]trunk/src_garrysmod/public/Lua/llex.c [/li][li]trunk/src_garrysmod/public/Lua/llex.h [/li][li]trunk/src_garrysmod/public/Lua/lparser.c[/li][/ul]

Committed By Garry Newman

Nice, thanks!



Finally, gonna re-write my code for this, looks alot nicer :3:

Can anybody explain how this is used?

[lua]for i=1, 10

if ( i < 5 ) then continue end

print( i )


would print 5 onwards


Also, real world example…

[lua]function gmsave.EntitySaveList( ents )

local tabEnts = {}
local savedEnts = {}
local SaveName = 1

for k, v in pairs( ents ) do

	if ( !IsValid( v ) ) then continue end
	local t = gmsave.EntitySave( v )
	if ( !gmsave.ShouldSaveEntity( v, t ) ) then continue end
	v.GMSaveName = "ent" .. SaveName;
	tabEnts[ v.GMSaveName ] = t;
	savedEnts[ v.GMSaveName ] = v
	SaveName = SaveName + 1

return tabEnts, savedEnts;


It skips to the next iteration in the loop.

[lua]for i=1, 5 do
if i == 3 then

Msg(i, ", ")


The output would be "1, 2, 4, 5, ".

Ah I see thanks for explaining :3

continue is useful thanks garry.

Wow fuck yes, I was talking to a shitload of people about howto achieve this like a week ago, it’s like you read my mind! :smiley:

Awesome. No more if blocks in entire loops.


Yes :razz:!

Fuck yeah, this is amazing

Nice to see this addition. Still unclear to me, why lua hasn’t this from default.

it should be named “skip” :smiley:


Garry rewrote Lua to work with CStyle syntax, maybe he removed it then?

Lua has never had native continue afaik.