Defining functions in geekest mode
totalgee opened this issue · 2 comments
Hi there, this is a great project! I like the "geekest" mode, where you have a few extra helpers and definitions like snoise2D()
available, and don't need to write the main()
definition. However, this means you can't create/use helper functions. Since the calling code just wraps the main()
definition before and adds a closing brace afterwards, it is actually possible to define functions after, like this (which compiles fine under geekest 300 es):
vec2 uv = (FC.xy - 0.5*r) / r.y * 1.;
for (int i = 0; i < 8; ++i) {
uv = abs(uv) / dot(uv, uv) - 0.7 + sin(t*0.75) * 0.2;
uv += snoise3D(vec3(uv * 0.2, 0.01*t)) * 0.25;
}
o.xyz = (1. - vec3(pow(length(uv), 0.25))) * hsv(sin(uv.x*PI + t),1.,1.) * 2.;
} // end of main()
float test(float x) {
return x * 2.;
// Note: no closing brace because it's provided by the wrapper!
However, you can't call test()
, because it's not declared before main()
. Besides #define
macros, is there no "hack" to allow you to define and call functions in geekest mode? Otherwise, could the helper methods (and FC
) be also exposed in geeker mode? Basically, what I'd like would be a "geekest" mode that allows you to write the main()
definition. Maybe the code could check if it finds a void main()
in the code, and if so, doesn't wrap it.
(I've made a PR with a possible solution for this.)
I've merged the PR and will close it.