From de855f30d527a9d30314c2109bdb709240305cbc Mon Sep 17 00:00:00 2001 From: xpol Date: Fri, 4 Nov 2016 11:37:38 +0800 Subject: [PATCH 1/2] Better love.arg.parse_options(): 1. use string.match for we are mean to match 2. better match pattern which now do not allow somthing like `not-a-valid--console` 3. use while loop which allows change loop var. --HG-- branch : better-parse-options --- src/scripts/boot.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/scripts/boot.lua b/src/scripts/boot.lua index 552827e1d..e3de9d4ed 100644 --- a/src/scripts/boot.lua +++ b/src/scripts/boot.lua @@ -134,15 +134,17 @@ function love.arg.parse_options() local game local argc = #arg - for i=1,argc do + local i = 1 + while i <= argc do -- Look for options. - local s, e, m = string.find(arg[i], "%-%-(.+)") + local m = string.match(arg[i], "^%-%-(.+)") if m and love.arg.options[m] then i = love.arg.parse_option(love.arg.options[m], i+1) elseif not game then game = i end + i = i + 1 end if not love.arg.options.game.set then From c28a6c51c49c5d1acba4645e3f29097d3fa010a3 Mon Sep 17 00:00:00 2001 From: Xpol Wan Date: Fri, 4 Nov 2016 22:27:49 +0800 Subject: [PATCH 2/2] love.arg.parse_option just return how many extra arg the current option consumes. --HG-- branch : better-parse-options --- src/scripts/boot.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/scripts/boot.lua b/src/scripts/boot.lua index e3de9d4ed..50b31c6e6 100644 --- a/src/scripts/boot.lua +++ b/src/scripts/boot.lua @@ -122,11 +122,10 @@ function love.arg.parse_option(m, i) m.arg = {} for j=i,i+m.a-1 do table.insert(m.arg, arg[j]) - i = j end end - return i + return m.a end function love.arg.parse_options() @@ -140,7 +139,7 @@ function love.arg.parse_options() local m = string.match(arg[i], "^%-%-(.+)") if m and love.arg.options[m] then - i = love.arg.parse_option(love.arg.options[m], i+1) + i = i + love.arg.parse_option(love.arg.options[m], i+1) elseif not game then game = i end