script lua chunk
Posted: Mon Jul 29, 2024 7:40 am
I use this method to load lua file as a script : https://love2d.org/wiki/love.filesystem.load
The script should contain 3 functions create, draw and update but not globaly defined but as local. So at the end of the script i need to put a table and return it.
Looks nice? Not that much. Any idea of how i can call a function defined in a chunk without returning it at the end as a variable which contains the functions prepared? Something like chunk.draw() or chunk.update() or perhaps chunk(params)? to call the update(params) when needed?
The script should contain 3 functions create, draw and update but not globaly defined but as local. So at the end of the script i need to put a table and return it.
Looks nice? Not that much. Any idea of how i can call a function defined in a chunk without returning it at the end as a variable which contains the functions prepared? Something like chunk.draw() or chunk.update() or perhaps chunk(params)? to call the update(params) when needed?
Code: Select all
local function create()
end
local function draw()
end
local function update()
end
-- i define a table here to export the functions
local shader = {
create = create,
draw = draw,
update = update,
}
-- glsl shader code
shader.glsl = [[
extern number time;
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords)
{
return vec4((1.0+sin(time))/2.0, abs(cos(time)), abs(sin(time)), 1.0);
}
]]
-- glsl shader parameters
shader.params = {
-- time that the shader uses in update
time = 0,
}
return shader