feat: add kind parameter for beginShape function (supporting LINES, POINTS, TRIANGLE_FAN, TRIANGLE_STRIP, and TRIANGLES)#13
Conversation
…RIANGLES, TRIANGLE_STRIP, TRIANGLE_FAN with fill and stroke
…RIANGLE_STRIP, and TRIANGLES
…_FAN in endShape function
|
Excellent. I just tested all of your example code plus the original versions on Processing's beginShape() reference page. Before merging, I thought worth considering one minor thing. What do you think we should return for incorrect passed kind parameters and un-implemented QUADS, QUAD_STRIP, TESS? Currently, there isn't error checking for incorrect Afterwards, we also need to update the vertex() reference page (to add info about u,v params) and the beginShape reference pages for info on |
|
I wrote this code in L5.lua to handle the error you've mentioned : function beginShape(_kind)
if(_kind ~= nil and not L5_env.shapeKinds[_kind]) then -- Lu_env.shapeKinds = {[POINTS]=true, [TRIANGLES]=true, ...}
error(_kind .. "is not defined" , 2)
end
-- reset custom shape vertices table
L5_env.vertices = {}
L5_env.useTexture = false
L5_env.kind = _kind
endIn Lua, any undefined global variable return nil, so if I called I think to override the returning nil behavior for the undefined variables or it adds overhead? Do you suggest another way to handle this error? |
|
Okay, good to brainstorm this. Unfortunately, I don't think that approach will work since there's no way to catch an undefined variable inside the function. Imagine someone passes an empty variable like BLAH, it will be undefined/nil, which will skip past the |
|
To be clear, I'm saying that |
|
I got to this approach function beginShape(...)
local n = select('#' , ...)
local _kind = select(1, ...)
if(n > 0 and _kind == nil) then
error(_kind .. "is not defined" , 2)
end
if _kind ~= nil and not L5_env.shapeKinds[_kind] then -- to check if you pass strings
error(_kind .. " is not defined", 2)
end
-- reset custom shape vertices table
L5_env.vertices = {}
L5_env.useTexture = false
L5_env.kind = _kind
endbut we can't print the I think we need to override the returning nil behavior for undefined variables to print |
I want to know your feedback @lee2sman
Examples :