Skip to content

Commit

Permalink
event docs
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasvlevi committed May 8, 2024
1 parent 531ad60 commit 4492984
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 78 deletions.
93 changes: 92 additions & 1 deletion src/bindings/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,98 @@
* @param k The keyboard key to check
*
* @return boolean Whether or not the key is down
*/
*/
int isKeyDown(lua_State *L);

/**
* @brief mousePressed
*
* Called when a mouse button is pressed.
*
* @param button The pressed mouse button
*
* <br/>
* In the following example, the circle's size increases when the user clicks the mouse.
*
* @example
* size = 0;
*
* function setup()
* createWindow(400, 400);
* end
*
* function draw()
* background(51);
*
* circle(mouseX, mouseY, size);
* end
*
* -- Increase circle size when mouse pressed
* function mousePressed()
* size = size + 1;
* end
* @example
*
*/

/**
* @brief mouseReleased
*
* Called when a mouse button is released.
*
* @param button The released mouse button
*
* <br/>
* In the following example, the circle's size increases when the user clicks the mouse.
*
* @example
* size = 32;
*
* function setup()
* createWindow(400, 400);
* end
*
* function draw()
* background(51);
*
* circle(mouseX, mouseY, size);
* end
*
* -- Set larger circle size
* function mousePressed()
* size = 64;
* end
*
* -- Reset size
* function mouseReleased()
* size = 32;
* end
* @example
*/

/**
* @brief keyPressed
*
* Called whenever a key is pressed.
*
* @param key The pressed key
*
*/

/**
* @brief keyReleased
*
* Called whenever a key is released.
*
* @param key The released key
*/

/**
* @brief keyHeld
*
* Called whenever a key is held down.
*
* @param key The held key
*/

#endif
37 changes: 0 additions & 37 deletions src/lu5_event_callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,6 @@

#include <stdio.h>

/**
* @brief mousePressed
*
* Called when a mouse button is pressed.
* The mouse button is passed as the first argument
*/

/**
* @brief mouseReleased
*
* Called when a mouse button is released.
* The mouse button is passed as the first argument
*/

static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
{
if (!lu5.L) return;
Expand All @@ -40,29 +26,6 @@ static void mouse_button_callback(GLFWwindow* window, int button, int action, in
}
}


/**
* @brief keyPressed
*
* Called whenever a key is pressed.
* Key is passed as the first argument.
*/

/**
* @brief keyReleased
*
* Called whenever a key is released.
* Key is passed as the first argument.
*/

/**
* @brief keyHeld
*
* Called whenever a key is held down.
* Key is passed as the first argument.
*/


static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (!lu5.L) return;
Expand Down
17 changes: 12 additions & 5 deletions tasks/lib/components.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ local function Method(method)
end

local returnContent = '';
if (method['return'] ~= nil) then
if (method['_return'] ~= nil) then
returnContent = "<h4>Returns</h4><div class=\"param\">" ..
"<code class=\"name\">" .. method['return'].var .. "</code>" ..
"<span class=\"text desc\">" .. method['return'].description .. "</span>" ..
"<code class=\"name\">" .. method['_return'].var .. "</code>" ..
"<span class=\"text desc\">" .. method['_return'].description .. "</span>" ..
"</div>" ;
end

Expand All @@ -102,10 +102,17 @@ local function Method(method)
"</code></pre>";
end

local decorator = '';
if (method['is_event']) then
decorator = '<span class="decorator">Event</span>';
end

return
"<div class=\"method\" id=\"".. method.name .. "\">" ..

"<code>" .. get_declaration(method) .. "</code>" ..
'<div>'..
"<code>" .. get_declaration(method) .. "</code>" ..
decorator..
'</div>'..
"<p>" .. method.description .. "</p>" ..
"<h4>Arguments</h4>" ..
"<div class=\"params\">" ..
Expand Down
84 changes: 51 additions & 33 deletions tasks/lib/parse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,17 @@ function parse_description(comment)
local result = {};
for i=1, #lines do
-- filter only text
local tagmatch = string.match(lines[i], "%@");
local tagmatch = string.match(lines[i], "%@%w+");
if (tagmatch ~= nil) then
break;
-- Allow brief
if (string.match(tagmatch, '%@brief') ~= nil) then
-- Skip line
i = i + 1;
else
-- End of description
break;
end

end

local m = string.match(lines[i], "%s%*%s.+");
Expand Down Expand Up @@ -139,7 +147,7 @@ end

function parse_return(comment)
local lines = split(comment, '\n');
local result = {};

for i=1, #lines do
-- filter only text
local m = string.match(comment, "@return%s[%w ,.?!]+");
Expand All @@ -149,14 +157,18 @@ function parse_return(comment)
table.remove(ws, 1);
table.remove(ws, 1);

-- TReturn
-- var: string
-- description: string
--
return {
var=var,
description=join(ws, ' ')
};
end
end

return result[0];
return nil;
end

function parse_example(comment)
Expand Down Expand Up @@ -189,51 +201,57 @@ function parse_example(comment)
return join(result, '\n');
end

function parse_comment(comment)

local matches = string.gmatch(comment, "@param .- .-%\n");

-- method
-- name: string
-- declaration: string
-- params: param[]
local method = {};

local lines = split(comment, '\n');

local dec = string.match(lines[#lines], 'int .-%(.*%)') .. ';';
function parse_comment(comment, name, is_event)
return {
name =name,
is_event =is_event,
description =parse_description(comment),
example =parse_example(comment),
bottom_description=parse_bottom_description(comment),
params =parse_params(comment),
_return =parse_return(comment)
};
end

dec = dec:gsub('lu5_', '');
function parse_params(comment)
local params = {};

method['name'] = split(split(dec, ' ')[2], '(')[1];
method['declaration'] = dec;
method['description'] = parse_description(comment);
method['bottom_description'] = parse_bottom_description(comment);
method['params'] = {};
method['return'] = parse_return(comment);
method['example'] = parse_example(comment);

-- get params
local matches = string.gmatch(comment, "@param .- .-%\n");
local index = 1;
for match in matches do

method['params'][index] = parse_param(match);
params[index] = parse_param(match);

index = index + 1;
end


return method;
return params;
end

function parse_header(source)
local matches = string.gmatch(source, "%/%*%*.-%*%/%s-%\nint .-%(.-%)");
local function_comments = string.gmatch(source, "%/%*%*.-%*%/%s-%\nint .-%(.-%)");
local callback_comments = string.gmatch(source, "%/%*%*%\n%s%*%s%@brief.-%*%/");
-- methods: method[]
local methods = {};

local index = 1;
for match in matches do
methods[index] = parse_comment(match);
for comment in function_comments do

-- Get declaration and name
local lines = split(comment, '\n');

-- TODO: Add error handling for nil values to enhance DX
local dec = string.match(lines[#lines], 'int .-%(.*%)'):gsub('lu5_', '') .. ';';
local name = split(split(dec, ' ')[2], '(')[1];

methods[index] = parse_comment(comment, name, false);
index = index + 1;
end

for comment in callback_comments do
-- TODO: Add error handling for nil values to enhance DX
local name = split(string.match(comment, '@brief.-%\n'), ' ')[2]:sub(1, -2);
methods[index] = parse_comment(comment, name, true);
index = index + 1;
end

Expand Down
16 changes: 14 additions & 2 deletions tasks/templates/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,22 @@ body {
height: fit-content;
}

a, p, span.text, h1, h2, h3, h4, h5, h6 {
a, p, span.text, span.decorator, h1, h2, h3, h4, h5, h6 {
font-family: "Trebuchet MS", Tahoma, sans-serif;
}

.decorator {
font-size: 18pt;
border-radius: 6px;
color: var(--white);
font-weight: bold;
background-color: var(--primary);

margin: 0 2.5rem;
padding: 0.2em 0.4em;

}

ul {
list-style-type: none;
margin: 0px;
Expand Down Expand Up @@ -212,7 +224,7 @@ pre code.hljs {
max-width: 87.5%;
}

.method > code {
.method > div > code {
font-size: 16pt;
}

Expand Down

0 comments on commit 4492984

Please sign in to comment.