root
enums.c
Functions
C Internal
func
pushEnums
→ void
line 221
// ↓ general push command for each enum list ↓
cross-refs:enums.h:?
func
testEnums
→ int
line 230
cross-refs:enums.h:? vanir.c:?
func
keyEnums
→ int
line 236
cross-refs:enums.h:? vanir.c:?
func
mouseButtonEnums
→ int
line 242
cross-refs:enums.h:? vanir.c:?
func
keyActionEnums
→ int
line 248
cross-refs:enums.h:? vanir.c:?
func
keyModEnums
→ int
line 254
cross-refs:enums.h:? vanir.c:?
func
cursorModeEnums
→ int
line 260
cross-refs:enums.h:? vanir.c:?
func
cursorShapeEnums
→ int
line 266
cross-refs:enums.h:? vanir.c:?
func
gamepadButtonEnums
→ int
line 272
cross-refs:enums.h:? vanir.c:?
func
gamepadAxisEnums
→ int
line 278
cross-refs:enums.h:? vanir.c:?
enums.h
Structs
typedef struct
Enums
line 9
cross-refs:enums.c:?
Externs
extern
test
Enums test[]
line 28
// ↓ enum declarations ↓
extern
keys
Enums keys[]
line 29
extern
mouseButtons
Enums mouseButtons[]
line 30
extern
keyActions
Enums keyActions[]
line 31
extern
keyMods
Enums keyMods[]
line 32
extern
cursorModes
Enums cursorModes[]
line 33
extern
cursorShapes
Enums cursorShapes[]
line 34
extern
gamepadButtons
Enums gamepadButtons[]
line 35
extern
gamepadAxes
Enums gamepadAxes[]
line 36
Macros
#define
VANIR
_ENUMS_H
line 4
lua_config.h
Macros
#define
lua
_rawlen(L, i) lua_objlen(L, i)
line 9
vanir.c
Functions
Lua
lua
requiredir
(string rel)
line 97
Lua stack args
1stringrel
Build the absolute path.
char cwd[PATH_MAX];
Skip hidden files and . / ..
if (name[0] == '.') continue;
Only load .lua files. Let Lua's require() handle native libs.
const char *ext = strrchr(name, '.');
Use luaL_loadfile + lua_pcall instead of luaL_dofile so we can
catch errors without aborting the whole directory scan.
if (luaL_loadfile(L, path) != LUA_OK) {Leave the error on the stack as a warning, then pop and continue.
if (luaL_loadfile(L, path) != LUA_OK) {
fprintf(stderr, "[Vanir] requiredir: load error in '%s': %s\n",
name, lua_tostring(L, -1));
lua_pop(L, 1);Call the chunk. Files that return a table get that table as the
result — we discard it here (requiredir isn't require()), but the
file ran and any side-effects (globals, hook registrations) stick.
if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
fprintf(stderr, "[Vanir] requiredir: runtime error in '%s': %s\n",
name, lua_tostring(L, -1));
lua
luaopen_vanir
→ LUALIB_API int
line 210
// / ↓ require("vanir") lua entry ↓ ///
C Internal
func
setFieldNumber
→ void
line 27
// ↓ helper functions ↓
Convenience wrapper that pushes a float onto the Lua stack and sets it as a named field on the table at the top of the stack.
Parameters
lua_State *LLua state.
const char *keyField name to set.
float dataFloat value to store.
cross-refs:vanir.h:? graphics/textures.c:? types/angle.c:? types/color.c:? types/matrix.c:? types/quaternion.c:? types/texture.c:? types/vector.c:?
func
registerGlobals
→ void
line 31
Iterates a luaL_Reg array, calls each function (which must push one value), and stores the result as a global in the Lua state. Used during luaopen_vanir to initialise module tables.
Parameters
lua_State* LLua state.
const luaL_Reg* funcsNULL-terminated luaL_Reg array. Each entry's func must push exactly one value.
func
quit
→ int
line 40
// ↑ helper functions ↑
Performs a full clean shutdown: releases all in-flight frames, destroys every pipeline and GLFW window, tears down the GPU context, and closes the Lua state before calling exit(0).
Parameters
lua_State *LLua state.
↓ close any in-flight frame on every window; ends pass encoder, releases view/texture ↓
for (int i = 0; i < windowPool.count; ++i) {
struct glfwWindow *w = windowPool.windows[i];↓ destroy per-window gpu resources; pipeline → surface unconfigure → surface release → glfw window ↓
for (int i = 0; i < windowPool.count; ++i) {
struct glfwWindow *w = windowPool.windows[i];↓ destroy pipeline first (uses GPU device) ↓
if (w->pipeline) {
destroyPipeline(w->pipeline);↓ unconfigure & release surface ↓
if (w->surface) {required before release on wgpu-native
if (w->surface) {
wgpuSurfaceUnconfigure(w->surface);
wgpuSurfaceRelease(w->surface);↓ destroy GLFW window ↓
if (w->window) {
glfwDestroyWindow(w->window);↓ release font and render target resources before gpu context goes away ↓
destroyAllFonts();
destroyAllRenderTargets();
destroyAllTextures();
destroyAllShaders();↓ release shared GPU context/glfw/and lua; device → adapter → instance ↓
device destroyed last
vanirGPUDestroy();
terminate GLFW after all windows gone
glfwTerminate();
close Lua state last
lua_close(L);
cross-refs:graphics/rendertarget.h:? graphics/shader.h:? graphics/textures.h:? modules/render.c:? modules/windows.c:? modules/windows.h:?
⚠ This function never returns. It calls exit(0) at the end.
Externs
extern
windowPool
struct windowPool windowPool
line 24
vanir.h
Functions
C Internal
func
vanir_throw_impl
→ static inline void
line 34
// ↓ error handling (clean) ↓
Macros
#define
VANIR
_H
line 2
#define
VANIR
_VERSION
line 4
#define
luaL
_reg luaL_Reg
line 14
#define
vanir
_log(fmt, ...) fprintf(stderr, fmt , ##__VA_A
line 24
#define
vanir
_log_info(fmt, ...) fprintf(stderr, fmt
line 25
#define
vanir
_log(fmt, ...) ((void)0)
line 27
#define
vanir
_log_info(fmt, ...) ((void)0)
line 28
#define
throw
(type, name, error) vanir_throw_impl((type), (name), (error)
line 50
// ↓ macro just injects file/line ↓
graphics/draw.c
Functions
Lua
lua
drawLine
(number x1, number y1, number x2, number y2)
line 205
// lua draw functions ↓↓↓ lua draw functions | ↓ all functions follow the same pattern; validate frame -> reserver space in cpu buffer -> push vertices -> record draw cmd ↓
Lua stack args
1numberx1
2numbery1
3numberx2
4numbery2
// ↑ webgpu does not support variable line width, make new function later ↑
cross-refs:graphics/render.h:? modules/render.c:?
lua
drawRect
(number x, number y, number bw, number bh)
line 232
Lua stack args
1numberx
2numbery
3numberbw
4numberbh
cross-refs:graphics/render.h:? modules/render.c:?
lua
drawCircle
(number x, number y, number radius, integer? arg4, function hasCb)
line 263
Lua stack args
1numberx
2numbery
3numberradius
4integer?arg4
5functionhasCb
cross-refs:graphics/render.h:? modules/render.c:?
lua
drawFilledCircle
(number x, number y, number radius, integer? arg4, function hasCb)
line 311
// ↓ center vertex gets average color of two surrounding edge ↓
Lua stack args
1numberx
2numbery
3numberradius
4integer?arg4
5functionhasCb
Pre-sample one color per edge vertex (0..segs-1), then assemble.
for (int i = 0; i < segs; ++i) {
pushVert(p, x, y, 0, c.r, c.g, c.b, c.a);
pushVert(p, px[i], py[i], 0, c.r, c.g, c.b, c.a);
pushVert(p, px[i+1], py[i+1], 0, c.r, c.g, c.b, c.a);
}
} else {This ensures each color is fetched exactly once and the center
can blend smoothly between its two neighbours.
struct color *ec = alloca((segs + 1) * sizeof(struct color));
close the loop
ec[segs] = ec[0];
Center gets the average of the two surrounding edge colors.
for (int i = 0; i < segs; ++i) {
struct color cc = {
(ec[i].r + ec[i+1].r) * 0.5f,
(ec[i].g + ec[i+1].g) * 0.5f,
(ec[i].b + ec[i+1].b) * 0.5f,
(ec[i].a + ec[i+1].a) * 0.5f,
};cross-refs:graphics/render.h:? modules/render.c:?
lua
drawPoly
(function hasCb)
line 379
// ↓ pre-samples all colors before fan loop so vertex 0's color is only fetched once ↓
Lua stack args
2functionhasCb
↓ pre-sampling happens here ↓
for (int i = 1; i < n - 1; ++i) {
pushVert(p, vx[0], vy[0], vz[0], c.r, c.g, c.b, c.a);
pushVert(p, vx[i], vy[i], vz[i], c.r, c.g, c.b, c.a);
pushVert(p, vx[i+1], vy[i+1], vz[i+1], c.r, c.g, c.b, c.a);
}
} else {
struct color *vc = alloca(n * sizeof(struct color));Lua 1-indexed
for (int i = 0; i < n; ++i) {
callColorCb(L, 2, i + 1);
getGlobalColor(&vc[i]);
}cross-refs:graphics/render.h:? modules/render.c:?
lua
drawVertex
(number x, number y, number z)
line 440
Lua stack args
1numberx
2numbery
3numberz
cross-refs:graphics/render.h:? modules/render.c:?
lua
drawRectOutline
(number arg1, number arg2, number arg3, number arg4, nil? t)
line 467
// render.drawRectOutline(x, y, w, h [, thickness]) | thickness <= 1: four line pairs. thickness > 1: four filled rects.
Lua stack args
1numberarg1
2numberarg2
3numberarg3
4numberarg4
5nil?t
thick outline: four filled border rects
pushVert(p, x, y, 0, c.r,c.g,c.b,c.a);
pushVert(p, x+bw, y, 0, c.r,c.g,c.b,c.a);
pushVert(p, x+bw, y, 0, c.r,c.g,c.b,c.a);
pushVert(p, x+bw, y+bh, 0, c.r,c.g,c.b,c.a);
pushVert(p, x+bw, y+bh, 0, c.r,c.g,c.b,c.a);
pushVert(p, x, y+bh, 0, c.r,c.g,c.b,c.a);
pushVert(p, x, y+bh, 0, c.r,c.g,c.b,c.a);
pushVert(p, x, y, 0, c.r,c.g,c.b,c.a);
pushCmd(p, DRAW_LINES, 8);
} else {
if (!vertReserve(p, 24))
return 0;top
pushVert(p, x, y, 0, c.r,c.g,c.b,c.a); pushVert(p, x+bw, y, 0, c.r,c.g,c.b,c.a); pushVert(p, x+bw, y+t, 0, c.r,c.g,c.b,c.a);
pushVert(p, x, y, 0, c.r,c.g,c.b,c.a); pushVert(p, x+bw, y+t, 0, c.r,c.g,c.b,c.a); pushVert(p, x, y+t, 0, c.r,c.g,c.b,c.a);bottom
pushVert(p, x, y+bh-t, 0, c.r,c.g,c.b,c.a); pushVert(p, x+bw, y+bh-t, 0, c.r,c.g,c.b,c.a); pushVert(p, x+bw, y+bh, 0, c.r,c.g,c.b,c.a);
pushVert(p, x, y+bh-t, 0, c.r,c.g,c.b,c.a); pushVert(p, x+bw, y+bh, 0, c.r,c.g,c.b,c.a); pushVert(p, x, y+bh, 0, c.r,c.g,c.b,c.a);left
pushVert(p, x, y+t, 0, c.r,c.g,c.b,c.a); pushVert(p, x+t, y+t, 0, c.r,c.g,c.b,c.a); pushVert(p, x+t, y+bh-t, 0, c.r,c.g,c.b,c.a);
pushVert(p, x, y+t, 0, c.r,c.g,c.b,c.a); pushVert(p, x+t, y+bh-t, 0, c.r,c.g,c.b,c.a); pushVert(p, x, y+bh-t, 0, c.r,c.g,c.b,c.a);right
pushVert(p, x+bw-t, y+t, 0, c.r,c.g,c.b,c.a); pushVert(p, x+bw, y+t, 0, c.r,c.g,c.b,c.a); pushVert(p, x+bw, y+bh-t, 0, c.r,c.g,c.b,c.a);
pushVert(p, x+bw-t, y+t, 0, c.r,c.g,c.b,c.a); pushVert(p, x+bw, y+bh-t, 0, c.r,c.g,c.b,c.a); pushVert(p, x+bw-t, y+bh-t, 0, c.r,c.g,c.b,c.a);
pushCmd(p, DRAW_TRIS, 24);
}cross-refs:graphics/render.h:? modules/render.c:?
lua
drawTriangle
(number arg1, number arg2, number arg3, number arg4, number arg5, number arg6)
line 525
// render.drawTriangle(x1, y1, x2, y2, x3, y3)
Lua stack args
1numberarg1
2numberarg2
3numberarg3
4numberarg4
5numberarg5
6numberarg6
cross-refs:graphics/render.h:? modules/render.c:?
lua
drawRoundedBox
(number arg1, number arg2, number arg3, number arg4, number arg5)
line 677
// render.drawRoundedBox(r, x, y, w, h)
Lua stack args
1numberarg1
2numberarg2
3numberarg3
4numberarg4
5numberarg5
cross-refs:graphics/render.h:? modules/render.c:?
lua
drawRoundedBoxEx
(number arg1, number arg2, number arg3, number arg4, number arg5, nil? tl, nil? tr, nil? bl, nil? br)
line 689
// render.drawRoundedBoxEx(r, x, y, w, h [, tl, tr, bl, br]) | Per-corner rounding: pass false to get a square corner instead
Lua stack args
1numberarg1
2numberarg2
3numberarg3
4numberarg4
5numberarg5
6nil?tl
7nil?tr
8nil?bl
9nil?br
cross-refs:graphics/render.h:? modules/render.c:?
lua
drawTexturedRectUV
(number arg1, number arg2, number arg3, number arg4, number arg5, number arg6, number arg7, number arg8)
line 706
// render.drawTexturedRectUV(x, y, w, h, startU, startV, endU, endV) | Draws the active texture stretched to the given rect with explicit UV coords
Lua stack args
1numberarg1
2numberarg2
3numberarg3
4numberarg4
5numberarg5
6numberarg6
7numberarg7
8numberarg8
cross-refs:graphics/render.h:? modules/render.c:?
lua
drawTexturedTriangleUV
(table arg1, table arg2, table arg3)
line 726
// render.drawTexturedTriangleUV(vert1, vert2, vert3) | Each vert is a table {x, y [, u, v]}. UV is accepted but currently ignored — | the vertex format (x y z r g b a) has no UV channel; draws a flat-colored tri.
Lua stack args
1tablearg1
2tablearg2
3tablearg3
cross-refs:graphics/render.h:? modules/render.c:?
lua
drawPixelsRGB
(integer arg1, integer arg2, table arg3, table arg4, table arg5)
line 762
// render.drawPixelsRGB(w, h, dataR, dataG, dataB) | Each data table is a flat 1-indexed array of integers 0-255, length w*h. | Uploads as a scratch texture and draws it at (0, 0) at native size.
Lua stack args
1integerarg1
2integerarg2
3tablearg3
4tablearg4
5tablearg5
↓ upload and draw as a scratch texture ↓
struct Texture *tex = textureUpload("__drawPixelsRGB_scratch__", pixels, (uint32_t)pw, (uint32_t)ph);cross-refs:graphics/render.h:? modules/render.c:?
lua
drawPixelsSubrectRGB
(number arg1, number arg2, number arg3, number arg4, number arg5, number arg6, integer arg7, integer arg8, table arg9, table arg10, table arg11)
line 811
// render.drawPixelsSubrectRGB(dstX, dstY, srcX, srcY, srcW, srcH, subrectW, subrectH, dataR, dataG, dataB) | Draws a subrect of a pixel buffer at (dstX, dstY).
Lua stack args
1numberarg1
2numberarg2
3numberarg3
4numberarg4
5numberarg5
6numberarg6
7integerarg7
8integerarg8
9tablearg9
10tablearg10
11tablearg11
srcW / srcH unused here — subrectW/H define the full buffer size
int srW = (int)luaL_checkinteger(L, 7);
int srH = (int)luaL_checkinteger(L, 8);↓ compute UV subrect within the uploaded texture ↓
float srcWf = (float)luaL_checknumber(L, 5);
float srcHf = (float)luaL_checknumber(L, 6);
float u0 = srcX / srcWf;
float v0 = srcY / srcHf;
float u1 = (srcX + (float)srW) / srcWf;
float v1 = (srcY + (float)srH) / srcHf;cross-refs:graphics/render.h:? modules/render.c:?
C Internal
func
vertReserve
→ static bool
line 28
// ↓ batch helpers ↓ | ↓ all draw calls within a frame accumulate vertices into flat array, cmd list, and at stopRender(), flushBatches() uploads everything in one buffer and walks cmd list ↓ | ↓ reserves double in size each time to amortize reallocs ↓
func
cmdReserve
→ static bool
line 52
func
pushVert
→ static void
line 79
// ↓ push one vertex into the flat buffer; applies the active matrix transform ↓
cross-refs:modules/render.c:?
func
pushCmd
→ static void
line 95
// ↓ record a draw command for the vertices just pushed; if same type and contiguous then extend ↓
func
flushBatches
→ void
line 118
// ↑ batch helpers ↑ | ↓ gpu flush, called by stopRender in render.c ↓
↓ bind buffer once, and walk cmd in order; switches pipeline on type ↓
wgpuRenderPassEncoderSetVertexBuffer(w->frame.passEncoder, 0, p->vertexBuffer, 0, needed);
↓ reset batch counter for next frame, allocations are kept ↓
p->vertCount = 0;
p->cmdCount = 0;cross-refs:graphics/render.h:? graphics/rendertarget.c:? graphics/shader.c:? modules/render.c:?
func
callColorCb
→ static void
line 180
// ↓ per vertex color callback helper ↓
func
circlePoints
→ static void
line 187
// ↓ precompute all point positions along circumference, avoids repeat sin/cos ↓
func
pushArc
→ static void
line 555
// ↓ push a filled arc as a triangle fan from (cx,cy); used by rounded box corners ↓
func
drawRoundedBoxInternal
→ static int
line 569
// ↓ internal: draw a rounded rect, per-corner rounding flags ↓
↓ clamp radius so it never exceeds half the shorter side ↓
float maxR = (bw < bh ? bw : bh) * 0.5f;
↓ 3 body rects (center + left strip + right strip) = 18 verts ↓
if (!vertReserve(p, 18)) return 0;
center rect
pushVert(p, x+r, y, 0, cr,cg,cb,ca); pushVert(p, x+bw-r, y, 0, cr,cg,cb,ca); pushVert(p, x+bw-r, y+bh, 0, cr,cg,cb,ca);
pushVert(p, x+r, y, 0, cr,cg,cb,ca); pushVert(p, x+bw-r, y+bh, 0, cr,cg,cb,ca); pushVert(p, x+r, y+bh, 0, cr,cg,cb,ca);left strip
pushVert(p, x, y+r, 0, cr,cg,cb,ca); pushVert(p, x+r, y+r, 0, cr,cg,cb,ca); pushVert(p, x+r, y+bh-r, 0, cr,cg,cb,ca);
pushVert(p, x, y+r, 0, cr,cg,cb,ca); pushVert(p, x+r, y+bh-r, 0, cr,cg,cb,ca); pushVert(p, x, y+bh-r, 0, cr,cg,cb,ca);right strip
pushVert(p, x+bw-r, y+r, 0, cr,cg,cb,ca); pushVert(p, x+bw, y+r, 0, cr,cg,cb,ca); pushVert(p, x+bw, y+bh-r, 0, cr,cg,cb,ca);
pushVert(p, x+bw-r, y+r, 0, cr,cg,cb,ca); pushVert(p, x+bw, y+bh-r, 0, cr,cg,cb,ca); pushVert(p, x+bw-r, y+bh-r, 0, cr,cg,cb,ca);
pushCmd(p, DRAW_TRIS, 18);↓ four corners: rounded arc or square fill depending on flag ↓
int arcVerts = segs * 3;
int cornerVerts = tl ? arcVerts : 6;Externs
extern
gpu
struct VanirGPU gpu
line 9
extern
activeShader
struct Shader *activeShader
line 16
Macros
#define
VERTEX
_STRIDE 7 // x y z r g b a
line 18
#define
VERTEX
_BYTES (VERTEX_STRIDE * sizeof(float))
line 19
#define
M
_PI 3.14159265358979323846
line 22
graphics/render.h
Macros
#define
GRAPHICS
_H
line 2
graphics/rendertarget.c
Functions
Lua
lua
renderTargetCreate
(string name, integer? arg2, integer? arg3)
line 140
// ↓ render.createRenderTarget(name [, width, height]) → Texture ↓ | ↓ loosely like Starfall's render.createRenderTarget; defaults to 512x512 ↓
Lua stack args
1stringname
2integer?arg2
3integer?arg3
↓ grow pool ↓
struct RenderTarget **temp = realloc(rtPool.targets, (rtPool.count + 1) * sizeof(struct RenderTarget *));
cross-refs:graphics/rendertarget.h:? modules/render.c:?
lua
renderTargetClear
(table arg2)
line 367
// ↓ render.clearRenderTarget(tex [, color]) ↓
Lua stack args
2tablearg2
↓ open a one-shot clear pass ↓
WGPUCommandEncoderDescriptor enc_desc = {0};
WGPUCommandEncoder enc = wgpuDeviceCreateCommandEncoder(gpu.device, &enc_desc);cross-refs:graphics/rendertarget.h:? modules/render.c:?
lua
renderTargetSetTexture
(number? arg2, number? arg3, number? arg4, number? arg5, number? arg6, number? arg7, number? arg8, number? arg9)
line 415
// ↓ draw an RT as a textured quad on the current window ↓ | ↓ render.setRenderTargetTexture(tex, sx, sy, sw, sh, dx, dy [, dw, dh]) ↓ | ↓ sx/sy/sw/sh = source region on the RT; dx/dy/dw/dh = destination rect on the window ↓ | ↓ dw/dh default to sw/sh ↓
Lua stack args
2number?arg2
3number?arg3
4number?arg4
5number?arg5
6number?arg6
7number?arg7
8number?arg8
9number?arg9
↓ ensure there is an open render pass to draw into ↓
if (!w->frame.passEncoder) {
throw("setRenderTargetTexture", tex->name, "no active render pass — call selectRender first");↓ compute UV coords from source rect ↓
float u0 = sx / (float)tex->width;
float v0 = sy / (float)tex->height;
float u1 = (sx + sw) / (float)tex->width;
float v1 = (sy + sh) / (float)tex->height;cross-refs:graphics/rendertarget.h:? modules/render.c:?
C Internal
func
buildSampleBindGroup
→ static bool
line 29
// ↓ build sampler bind group layout + bind group for sampling this RT as a texture ↓
↓ layout: binding 0 = texture, binding 1 = sampler ↓
WGPUBindGroupLayoutEntry entries[2] = {0};
func
allocTexture
→ static bool
line 92
// ↓ (re)allocate the backing texture at a given size ↓
↓ release old resources ↓
if (tex->bindGroup) { wgpuBindGroupRelease(tex->bindGroup); tex->bindGroup = NULL; }
if (tex->bindGroupLayout) { wgpuBindGroupLayoutRelease(tex->bindGroupLayout); tex->bindGroupLayout = NULL; }
if (tex->sampler) { wgpuSamplerRelease(tex->sampler); tex->sampler = NULL; }
if (tex->view) { wgpuTextureViewRelease(tex->view); tex->view = NULL; }
if (tex->texture) { wgpuTextureRelease(tex->texture); tex->texture = NULL; }↓ match the swapchain format so CopyTextureToTexture succeeds ↓
tex->width = w;
tex->height = h;
tex->format = (windowPool.count > 0) ? windowPool.windows[0]->surfaceFormat : WGPUTextureFormat_BGRA8Unorm;
func
renderTargetSelect
→ int
line 212
// ↓ open an off-screen render pass into this RT; draw calls will go here ↓ | ↓ render.selectRenderTarget(tex) ↓
↓ fill the proxy glfwWindow so draw calls flow into the RT pass ↓
memset(&rtProxy, 0, sizeof(rtProxy));
↓ borrow the pipeline from the first real window for uniform bind group ↓
if (windowPool.count > 0) {
struct glfwWindow *mainWin = windowPool.windows[0];
rtProxy.pipeline = mainWin->pipeline;↓ update viewport uniform to RT dimensions ↓
if (mainWin->pipeline && mainWin->pipeline->uniformBuffer) {
float vp[2] = { (float)tex->width, (float)tex->height };
wgpuQueueWriteBuffer(gpu.queue, mainWin->pipeline->uniformBuffer, 0, vp, sizeof(vp));
}↓ set pipeline on the RT pass ↓
if (rt->passEncoder && mainWin->pipeline->pipeline) {
wgpuRenderPassEncoderSetPipeline(rt->passEncoder, mainWin->pipeline->pipeline);
if (mainWin->pipeline->uniformBindGroup)
wgpuRenderPassEncoderSetBindGroup(rt->passEncoder, 0, mainWin->pipeline->uniformBindGroup, 0, NULL);
}
}↓ redirect draw calls to the proxy ↓
prevRenderWindow = currentRenderWindow;
currentRenderWindow = &rtProxy;cross-refs:graphics/rendertarget.h:? modules/render.c:?
func
renderTargetStop
→ int
line 300
// ↓ finish and submit the RT render pass ↓ | ↓ render.stopRenderTarget() ↓
↓ sync proxy pass back in case draw calls swapped it ↓
rt->passEncoder = rtProxy.frame.passEncoder;
↓ flush any batched geometry accumulated during RT draw calls ↓
↓ must happen before ending the pass or it bleeds into the next window flush ↓
if (rtProxy.frame.passEncoder) {
vanir_log_info("stopRenderTarget: \"%s\" flushing batches", rt->tex.name);
flushBatches(&rtProxy);↓ sync back after flushBatches may have swapped passEncoder ↓
rt->passEncoder = rtProxy.frame.passEncoder;
}↓ restore previous render target and re-upload that window's viewport ↓
currentRenderWindow = prevRenderWindow;
prevRenderWindow = NULL;
currentRT = NULL;cross-refs:graphics/rendertarget.h:? modules/render.c:?
func
destroyAllRenderTargets
→ void
line 454
cross-refs:vanir.c:? graphics/rendertarget.h:?
Externs
extern
gpu
struct VanirGPU gpu
line 14
extern
windowPool
struct windowPool windowPool
line 16
graphics/rendertarget.h
Structs
struct
RenderTarget
line 13
// ↓ an off-screen render target; can be drawn into and sampled as a texture ↓ | ↓ tex is a full Texture — pass it to render.setTexture, render.setMaterial, etc. ↓
// ↓ must be first; Lua receives &rt->tex directly ↓// ↓ encoder / pass for off-screen rendering into this target ↓// ↓ true between selectRenderTarget / stopRenderTarget ↓
cross-refs:graphics/rendertarget.c:? modules/render.c:?
struct
RenderTargetPool
line 24
// ↓ global pool ↓
cross-refs:graphics/rendertarget.c:?
Externs
extern
rtPool
struct RenderTargetPool rtPool
line 29
Macros
#define
GRAPHICS
_RENDERTARGET_H
line 2
#define
VANIR
_MAX_RENDER_TARGETS 64
line 9
#define
rt
_from_tex(t) ((struct RenderTarget *)(t))
line 32
// ↓ recover the RenderTarget from a Texture pointer (tex is always the first field) ↓
graphics/shader.c
Functions
Lua
lua
luaShaderCompile
(string name, string src)
line 295
// ↓ Lua bindings ↓ | ↓ shader.compile(name, wgsl_source) ↓
Lua stack args
1stringname
2stringsrc
lua
luaShaderSetActive
(string name)
line 306
// ↓ shader.setActive(name) — draw calls use this pipeline instead of the built-in one ↓ | ↓ shader.setActive(nil) — revert to the built-in pipeline ↓
Lua stack args
1stringname
↓ restore the built-in pipeline on all windows ↓
for (int i = 0; i < windowPool.count; ++i) {
struct glfwWindow *w = windowPool.windows[i];↓ switch the render pass on any active windows immediately ↓
for (int i = 0; i < windowPool.count; ++i) {
struct glfwWindow *w = windowPool.windows[i];↓ flush pending geometry before switching pipeline ↓
if (p && p->cmdCount > 0)
flushBatches(w);
lua
luaShaderRelease
(string name)
line 363
// ↓ shader.release(name) ↓
Lua stack args
1stringname
lua
luaShaderExists
(string name)
line 394
Lua stack args
1stringname
lua
luaShaderGetActive
→ static int
line 404
// ↓ shader.getActive() — returns the name of the active custom shader, or nil ↓
Returns the name of the currently active custom shader, or nil if the built-in pipeline is in use.
Lua stack args
→returnstring shader name, or nil.
lua
luaShaderList
→ static int
line 414
// ↓ shader.list() — returns a table of all compiled shader names ↓
Returns an array table of the names of all currently compiled shaders in the shader pool.
Lua stack args
→returntable — sequential array of name strings, may be empty.
lua
luaShaderSetUniform
(string shaderName, string key, number val)
line 428
// ↓ uniform injection ↓ | ↓ shader.setUniform(name, key, value) — store a pending uniform for a named shader ↓ | ↓ values are stored as Lua numbers; send them to the GPU via shader.sendUniforms() ↓
Stores a named uniform value for a shader. Values are kept in the Lua registry and can be read back with shader.getUniform or iterated with shader.getUniforms. Wire them into your GPU uniform buffer update path to send them to WGSL.
Lua stack args
1stringshaderName
2stringkeystring — uniform variable name as used in WGSL.
3numberval
↓ uniforms table lives in the Lua registry: registry[shaderName] = { key = value, … } ↓
lua_pushstring(L, shaderName);
lua_gettable(L, LUA_REGISTRYINDEX);
lua
luaShaderGetUniform
(string shaderName, string key)
line 462
// ↓ shader.getUniform(name, key) — read back a stored uniform value, or nil ↓
Reads back a stored uniform value for a shader. Returns nil if the shader has no stored uniforms or the key was never set.
Lua stack args
1stringshaderName
2stringkeystring — uniform key.
→returnnumber, or nil.
↓ result is now on top; remove the table beneath it ↓
lua_remove(L, -2);
lua
luaShaderGetUniforms
(string shaderName)
line 485
// ↓ shader.getUniforms(name) — return the full uniform table for a shader (or nil) ↓
Returns the entire uniform table for a named shader as a plain Lua table (key → number), or nil if none have been set.
Lua stack args
1stringshaderName
→returntable of {key = value} pairs, or nil.
C Internal
func
shaderCompile
→ bool
line 34
// ↓ compile a WGSL source string into a RenderPipeline for triangle and line topology ↓ | ↓ the shader must follow the same vertex layout as the built-in pipeline ↓ | ↓ (location0=pos:vec3f, location1=color:vec4f) and expose vs_main/fs_main ↓
↓ release old shader with this name ↓
for (int i = 0; i < shaderPool.count; ++i) {
if (strcmp(shaderPool.shaders[i]->name, name) == 0) {
struct Shader *old = shaderPool.shaders[i];↓ vertex layout mirrors the built-in pipeline ↓
WGPUVertexAttribute attrs[2] = {0};
attrs[0].format = WGPUVertexFormat_Float32x3;
attrs[0].offset = 0;
attrs[0].shaderLocation = 0;
attrs[1].format = WGPUVertexFormat_Float32x4;
attrs[1].offset = 3 * sizeof(float);
attrs[1].shaderLocation = 1;↓ reuse the window's existing uniform bind group layout ↓
WGPUPipelineLayoutDescriptor pl_desc = {0};
pl_desc.bindGroupLayoutCount = 1;
pl_desc.bindGroupLayouts = &p->uniformBindGroupLayout;
WGPUPipelineLayout pl = wgpuDeviceCreatePipelineLayout(gpu.device, &pl_desc);↓ grow pool ↓
struct Shader **temp = realloc(shaderPool.shaders, (shaderPool.count + 1) * sizeof(struct Shader *));
cross-refs:graphics/shader.h:?
func
flushBatchesTextured
→ void
line 197
// ↓ flush pending geometry batches before switching pipelines ↓
cross-refs:graphics/shader.h:? modules/windows.h:?
func
drawTexturedQuadImmediate
→ void
line 203
// ↓ draw a textured quad directly (non-batched) into the current render pass ↓ | ↓ flushes any pending geometry first so draw order is preserved ↓
↓ flush pending geometry batches first ↓
if (p->cmdCount > 0)
flushBatches(w);↓ 6 vertices (2 triangles), 6 floats each: x y z w u v ↓
float verts[6 * TEXTURED_VERTEX_STRIDE] = {
dx, dy, 0, 1, u0, v0,
dx + dw, dy, 0, 1, u1, v0,
dx + dw, dy + dh, 0, 1, u1, v1,
dx, dy, 0, 1, u0, v0,
dx + dw, dy + dh, 0, 1, u1, v1,
dx, dy + dh, 0, 1, u0, v1,
};↓ create or reuse a small scratch vertex buffer ↓
WGPUBufferDescriptor buf_desc = {0};
buf_desc.usage = WGPUBufferUsage_Vertex | WGPUBufferUsage_CopyDst;
buf_desc.size = size;
buf_desc.mappedAtCreation = false;
WGPUBuffer vbuf = wgpuDeviceCreateBuffer(gpu.device, &buf_desc);↓ switch to textured pipeline and set bind groups ↓
wgpuRenderPassEncoderSetPipeline(w->frame.passEncoder, p->pipelineTextured);
↓ bind the texture's group at slot 1 ↓
wgpuRenderPassEncoderSetBindGroup(w->frame.passEncoder, 1, tex->bindGroup, 0, NULL);
↓ restore the solid-color pipeline so subsequent draw calls work correctly ↓
if (p->pipeline) {
wgpuRenderPassEncoderSetPipeline(w->frame.passEncoder, p->pipeline);cross-refs:graphics/draw.c:? graphics/render.h:? graphics/rendertarget.c:? graphics/shader.h:? graphics/textures.c:? modules/windows.h:?
func
destroyAllShaders
→ void
line 275
cross-refs:vanir.c:? graphics/shader.h:?
func
shaderInit
→ int
line 512
cross-refs:vanir.c:? graphics/shader.h:?
Externs
extern
gpu
struct VanirGPU gpu
line 12
extern
windowPool
struct windowPool windowPool
line 13
extern
?
void flushBatches(struct glfwWindow *w)
line 16
// ↓ from graphics/draw.c; declared here to avoid including graphics/render.h which has struct conflicts ↓
graphics/shader.h
Structs
struct
Shader
line 15
// ↓ a compiled custom WGSL shader with its pipeline ↓
// ↓ vertex attribute layout expected by the shader; defaults match the built-in layout ↓// bytes per vertex// ↓ true when the shader uses UV coords (location 2) ↓
cross-refs:graphics/draw.c:? graphics/shader.c:? modules/render.c:?
struct
ShaderPool
line 27
// ↓ global shader pool ↓
cross-refs:graphics/shader.c:?
Externs
extern
shaderPool
struct ShaderPool shaderPool
line 32
extern
activeShader
struct Shader *activeShader
line 36
// ↓ the currently active custom shader; NULL means the built-in pipeline is used ↓ | ↓ respected by beginPass in render.c whenever a new render pass opens ↓
Macros
#define
SHADER
_H
line 2
graphics/textures.c
Functions
Lua
lua
pushColorValue
→ static void
line 34
lua
drawTexturedRect
(number? arg1, number? arg2, number? arg3, number? arg4, number? arg5, number? arg6, number? arg7, number? arg8)
line 405
// ↓ draw a texture (or sub-region) as a quad using the textured pipeline ↓ | ↓ drawTexturedRect(sx, sy, sw, sh, dx, dy [, dw, dh]) ↓ | ↓ sx/sy/sw/sh = source region on the texture; dx/dy = destination on screen; dw/dh default to sw/sh ↓
Lua stack args
1number?arg1
2number?arg2
3number?arg3
4number?arg4
5number?arg5
6number?arg6
7number?arg7
8number?arg8
↓ compute normalised UV coords from source rect ↓
float u0 = sx / (float)tex->width;
float v0 = sy / (float)tex->height;
float u1 = (sx + sw) / (float)tex->width;
float v1 = (sy + sh) / (float)tex->height;cross-refs:graphics/shader.c:? graphics/textures.h:? modules/render.c:? types/texture.c:?
lua
luaTextureLoad
(string path, string? name)
line 447
// ↓ textures.load(path [, name]) → loads using stb_image; name defaults to path ↓ | ↓ requires stb_image.h in src/graphics/ and VANIR_HAS_STB_IMAGE compile flag ↓
Lua stack args
1stringpath
2string?name
↓ get file size ↓
size_t fileSize = 0;
FILE *f = fopen(path, "rb");
lua
luaTextureLoadFromPixels
(string name, integer arg2, integer arg3, string arg4)
line 508
// ↓ textures.loadFromPixels(name, width, height, pixels_string) ↓ | ↓ pixels_string is a raw RGBA8 byte string; width*height*4 bytes ↓
Lua stack args
1stringname
2integerarg2
3integerarg3
4stringarg4
↓ path stays NULL; channels/fileSize stay 0 — pixel data was provided directly ↓
lua
luaTextureGetSize
→ int
line 554
// ↓ textures.getSize(tex) → width, height (module-level convenience) ↓
C Internal
func
buildTextureBindGroup
→ static bool
line 58
// ↓ build a sampler + bind group for sampling this texture ↓
func
textureRelease
→ void
line 231
// ↓ free all GPU resources for a texture and remove it from the pool ↓
↓ compact pool ↓
texturePool.textures[i] = texturePool.textures[--texturePool.count];
cross-refs:graphics/draw.c:? graphics/textures.h:? types/texture.c:?
func
textureSetImage
→ bool
line 262
// ↓ load a new image from path into an existing texture; replaces GPU resources in-place ↓ | ↓ also updates tex->path so future :setImage() calls without args can use it ↓ | ↓ returns true on success; tex pointer stays valid ↓
↓ get file size ↓
size_t fileSize = 0;
FILE *f = fopen(path, "rb");↓ drop old GPU resources ↓
if (tex->bindGroup) { wgpuBindGroupRelease(tex->bindGroup); tex->bindGroup = NULL; }
if (tex->bindGroupLayout) { wgpuBindGroupLayoutRelease(tex->bindGroupLayout); tex->bindGroupLayout = NULL; }
if (tex->sampler) { wgpuSamplerRelease(tex->sampler); tex->sampler = NULL; }
if (tex->view) { wgpuTextureViewRelease(tex->view); tex->view = NULL; }
if (tex->texture) { wgpuTextureRelease(tex->texture); tex->texture = NULL; }
if (tex->pixels) { free(tex->pixels); tex->pixels = NULL; }↓ re-upload ↓
tex->pixels = malloc((size_t)(4 * w * h));
cross-refs:graphics/textures.h:? types/texture.c:?
func
textureGetColor
→ bool
line 374
// ↓ get a pixel color from cpu-side pixel data ↓
cross-refs:graphics/textures.h:? types/texture.c:?
func
destroyAllTextures
→ void
line 562
cross-refs:vanir.c:? graphics/textures.h:?
func
texturesInit
→ int
line 595
cross-refs:vanir.c:? graphics/textures.h:?
Externs
extern
gpu
struct VanirGPU gpu
line 22
extern
windowPool
struct windowPool windowPool
line 23
Macros
#define
STBI
_NO_THREAD_LOCALS
line 9
// stb_image ↓↓↓ stb_image
#define
STBI
_NO_SIMD
line 10
#define
STB
_IMAGE_IMPLEMENTATION
line 11
graphics/textures.h
Structs
struct
Texture
line 14
// ↓ a loaded GPU texture with its view, sampler, and bind group for sampling ↓
// ↓ bind group for use with the textured pipeline (group 1: binding 0 = tex, 1 = sampler) ↓// ↓ user-given label (defaults to path) ↓// ↓ original file path (NULL for loadFromPixels) ↓// ↓ original channel count from stb_image (0 if loadFromPixels) ↓// ↓ file size in bytes at load time (0 if loadFromPixels) ↓
cross-refs:graphics/draw.c:? graphics/render.h:? graphics/rendertarget.c:? graphics/rendertarget.h:? graphics/shader.c:? graphics/shader.h:? graphics/textures.c:? modules/render.c:? modules/render.h:? modules/windows.h:? types/common.h:? types/texture.c:?
struct
TexturePool
line 34
// ↓ global pool ↓
cross-refs:graphics/textures.c:?
Externs
extern
texturePool
struct TexturePool texturePool
line 39
Macros
#define
TEXTURES
_H
line 2
modules/files.c
Functions
Lua
lua
fileClose
(table arg1)
line 11
// ↓ file:close() ↓
Lua stack args
1tablearg1
lua
toStringFile
→ static int
line 35
lua
fileSeek
(integer arg2)
line 71
// ↓ file:seek(n) → None; seeks to absolute byte position ↓
Lua stack args
2integerarg2
lua
fileSkip
(integer arg2)
line 81
// ↓ file:skip(n) → number (resulting position) ↓
Lua stack args
2integerarg2
lua
fileRead
(integer arg2)
line 122
// ↓ file:read(n) → string (raw bytes) ↓
Lua stack args
2integerarg2
lua
fileWrite
(string arg2)
line 169
// ↓ file:write(str) ↓
Lua stack args
2stringarg2
lua
fileWriteByte
(integer arg2)
line 285
// --- typed writes --- | ↓ file:writeByte(x) ↓
Lua stack args
2integerarg2
lua
fileWriteBool
(boolean arg2)
line 295
// ↓ file:writeBool(x) ↓
Lua stack args
2booleanarg2
lua
fileWriteShort
(integer arg2)
line 305
// ↓ file:writeShort(x) ↓
Lua stack args
2integerarg2
lua
fileWriteUShort
(integer arg2)
line 315
// ↓ file:writeUShort(x) ↓
Lua stack args
2integerarg2
lua
fileWriteLong
(integer arg2)
line 325
// ↓ file:writeLong(x) ↓
Lua stack args
2integerarg2
lua
fileWriteULong
(integer arg2)
line 335
// ↓ file:writeULong(x) ↓
Lua stack args
2integerarg2
lua
fileWriteFloat
(number arg2)
line 345
// ↓ file:writeFloat(x) ↓
Lua stack args
2numberarg2
lua
fileWriteDouble
(number arg2)
line 355
// ↓ file:writeDouble(x) ↓
Lua stack args
2numberarg2
lua
fileWriteUInt64
(string arg2)
line 365
// ↓ file:writeUInt64(str) — decimal string ↓
Lua stack args
2stringarg2
lua
filesOpen
(string path, string? mode)
line 425
// ↓ files.open(path [, mode]) → File | nil ↓ | ↓ mode defaults to "rb"; use "wb" / "r+b" etc for write / read-write ↓
Lua stack args
1stringpath
2string?mode
lua
filesExists
(string path)
line 444
// ↓ files.exists(path) → boolean ↓
Lua stack args
1stringpath
lua
filesDelete
(string path)
line 459
// ↓ files.delete(path) → boolean ↓
Lua stack args
1stringpath
lua
filesRename
(string from, string to)
line 468
// ↓ files.rename(from, to) → boolean ↓
Lua stack args
1stringfrom
2stringto
C Internal
func
fileFlush
→ static int
line 53
// ↓ file:flush() ↓
func
fileTell
→ static int
line 62
// ↓ file:tell() → number ↓
func
fileSize
→ static int
line 92
// ↓ file:size() → number ↓
cross-refs:graphics/textures.c:? graphics/textures.h:? types/texture.c:?
func
fileEndOfFile
→ static int
line 107
// ↓ file:endOfFile() → boolean ↓
func
fileReadLine
→ static int
line 143
// ↓ file:readLine() → string ↓
↓ strip trailing newline ↓
size_t len = strlen(buf);
func
fileReadByte
→ static int
line 182
// --- typed reads --- | ↓ file:readByte() → number (UInt8) ↓
func
fileReadBool
→ static int
line 193
// ↓ file:readBool() → boolean ↓
func
fileReadShort
→ static int
line 204
// ↓ file:readShort() → number (Int16) ↓
func
fileReadUShort
→ static int
line 215
// ↓ file:readUShort() → number (UInt16) ↓
func
fileReadLong
→ static int
line 226
// ↓ file:readLong() → number (Int32) ↓
func
fileReadULong
→ static int
line 237
// ↓ file:readULong() → number (UInt32) ↓
func
fileReadFloat
→ static int
line 248
// ↓ file:readFloat() → number (Float32) ↓
func
fileReadDouble
→ static int
line 259
// ↓ file:readDouble() → number (Float64) ↓
func
fileReadUInt64
→ static int
line 270
// ↓ file:readUInt64() → string (decimal) ↓
func
filesInit
→ int
line 485
cross-refs:vanir.c:? modules/files.h:?
modules/files.h
Externs
extern
fileMethods
const luaL_Reg fileMethods[]
line 6
extern
fileMeta
const luaL_Reg fileMeta[]
line 7
Macros
#define
VANIR
_FILES_H
line 2
modules/font.c
Functions
C Internal
func
fontCreate
→ int
line 7
// ↓ font system stub; implement later ↓ | stubs ↓↓↓ stubs ///
func
fontSet
→ int
line 8
func
fontGetSize
→ int
line 9
func
fontMeasure
→ int
line 10
func
fontDrawText
→ int
line 11
func
destroyAllFonts
→ void
line 13
// stubs ↑↑↑ stubs ///
cross-refs:vanir.c:?
func
fontInit
→ int
line 25
cross-refs:vanir.c:? modules/font.h:?
modules/font.h
Macros
#define
FONT
_H
line 2
modules/hooks.c
Functions
Lua
lua
errorHandler
(string msg)
line 169
// ↓ pushed as the msgh argument to lua_pcall; baking full stack track using debug.traceback() ↓
Lua stack args
1stringmsg
↓ debug.traceback(msg, 2); skips this handler frame itself ↓
luaL_traceback(L, L, msg, 2);
leave the traceback string on the stack
return 1;
lua
luaFunc
→ void
line 190
// ↓ C trampoline that looks up the function by registry ref and pushes the callback arg ↓
stack: ... | msgh
lua_pushcfunction(L, errorHandler);
↓ lua_pcall's msgh index must be absolute ↓
int msgh = base + 1;
↓ push the lua function from the registry ↓
lua_rawgeti(L, LUA_REGISTRYINDEX, instance->stack[index].ref);
↓ remove the message handler from the stack ↓
lua_remove(L, msgh);
lua
luaAdd
(string hookName, string name, function arg3)
line 243
// ↓ lua interface for internal C functions ↓
Lua-callable hook.add — registers a callback under a named hook. If a callback with the same name already exists on that hook it is replaced in-place.
Lua stack args
1stringhookName
2stringname
3functionarg3
→returnNothing.
lua
luaRemove
(string hookName, string name)
line 265
Lua-callable hook.remove — unlinks a named callback from a hook. Safe to call even if the name was never added.
Lua stack args
1stringhookName
2stringname
lua
luaFree
(string hookName)
line 280
Lua stack args
1stringhookName
C Internal
func
createCallback
→ struct callbacks*
line 15
// ↓ allocate a new callback with given data size and type; carries typed value from C -> lua when fired ↓
Allocates a new callbacks struct with the given data buffer size and type tag. Used internally to pass typed C data into Lua hook callbacks.
Parameters
size_t dataSizeSize in bytes of the payload. Use sizeof() on the relevant type.
enum dataType dataTypeOne of the dataType enum values (number, string, integer, lua_bool, function).
→returnHeap-allocated pointer; the hook system owns this and frees it when the hook is freed.
cross-refs:modules/hooks.h:? modules/input.c:? modules/windows.c:?
func
setCallback
→ void
line 30
// helper functions ↓↓↓ helper functions
copies data into existing callback
memcpy(callback->data, data, callback->dataSize);
cross-refs:modules/hooks.h:? modules/input.c:? modules/windows.c:?
func
getCallback
→ void*
line 33
cross-refs:modules/hooks.h:?
func
fireError
→ void
line 40
// helper functions ↑↑↑ helper functions | ↓ fire the onError hook with a formatted message string; called by throwError below ↓
cross-refs:vanir.h:? modules/hooks.h:?
func
registerHook
→ void
line 51
// ↓ append hook to global pool; called once per hook during module init ↓
cross-refs:modules/hooks.h:? modules/input.c:? modules/windows.c:?
func
addHook
→ void
line 64
// ↓ listener stack; each hook has a stack of named listeners and main C handle ↓
↓ name not found, grow and append stack ↓
struct stack *temp = realloc(instance->stack, (instance->pool + 1) * sizeof(struct stack));
cross-refs:modules/hooks.h:?
func
removeHook
→ void
line 90
// ↓ frees the name, unrefs lua, then shifts remaining listeners down and shrinks the stack allocation ↓
↓ release the lua reg ref so the gc can collect the function ↓
if (instance->stack[i].ref != LUA_NOREF)
luaL_unref(L, LUA_REGISTRYINDEX, instance->stack[i].ref);
func
runHook
→ void
line 123
// ↓ singular hook call; calls C handle first, then every lua listener attached ↓
↓ main hook C handle ↓
if (instance->handle) {
instance->handle(instance, L);
}↓ hook_awaiting hook types are one-shot; they fire once before going idle ↓
if (instance->status == hook_awaiting) {
instance->status = hook_idle;
}cross-refs:modules/hooks.h:?
func
freeHook
→ void
line 153
// ↓ frees all listeners from a hook but keeps it registered ↓
cross-refs:modules/hooks.h:?
func
findHook
→ struct hook*
line 232
// ↓ find a hook in the global pool by name; returns NULL if not found ↓
cross-refs:modules/hooks.h:?
func
hooksRun
→ int
line 294
Runs all hooks currently in hook_awaiting or hook_update state. Called once per frame from update(). Fires callbacks in registration order.
Parameters
lua_State *LLua state.
// ↑ advance all named timers each frame ↑
cross-refs:vanir.c:? modules/hooks.h:?
⚠ Do not call this manually from Lua; the engine calls it automatically inside update().
func
hooksInit
→ int
line 314
cross-refs:vanir.c:? modules/hooks.h:?
modules/hooks.h
Structs
struct
callbacks
line 20
Carries a typed value from C code into a Lua hook callback. dataType determines how the void* data is interpreted when the callback fires.
cross-refs:modules/hooks.c:? modules/windows.c:?
struct
hookPool
line 26
Global array of all registered hooks. Iterated by hooksRun each frame.
cross-refs:modules/hooks.c:?
struct
hook
line 31
A named event slot. Holds a linked list of Lua callbacks (the stack), a status flag, and an optional typed payload for passing C data to Lua when the hook fires.
cross-refs:vanir.c:? modules/hooks.c:? modules/input.c:? modules/input.h:? modules/timer.c:? modules/timer.h:? modules/windows.c:? modules/windows.h:?
struct
stack
line 41
cross-refs:vanir.c:? modules/hooks.c:? modules/render.c:? types/common.h:? types/matrix.c:? types/texture.c:?
Enums
enum
dataType
line 6
Tag enum for the callbacks struct. Controls how the payload is marshalled into a Lua value when a hook fires.
number
string
integer
bool
function
cross-refs:modules/hooks.c:?
enum
status
line 14
Lifecycle flag for a hook. hook_idle means no pending fire; hook_awaiting means fire once next frame; hook_update means fire every frame.
awaiting
update
idle
cross-refs:modules/hooks.c:? modules/input.c:? modules/render.c:? modules/windows.c:?
Externs
extern
hookPool
struct hookPool hookPool
line 63
// callbacks ↑↑↑ callbacks ///
Global array of all registered hooks. Iterated by hooksRun each frame.
extern
onError
struct hook onError
line 64
modules/input.c
Functions
Lua
lua
getInputName
(integer arg1)
line 10
// ↓ reverse-lookup: code -> name string, checks keys then mouse buttons, nil if not found ↓
Lua stack args
1integerarg1
lua
getKey
(integer key)
line 43
Lua stack args
1integerkey
cross-refs:modules/input.h:?
C Internal
func
keyPressHandle
→ void
line 51
func
keyReleaseHandle
→ void
line 66
func
keyPressHandle
→ else
static void
line 88
func
keyReleaseHandle
→ static void
line 90
func
getKey
→ int
line 91
cross-refs:modules/input.h:?
func
cbKey
→ void
line 110
// ↓ glfw key callback; registered per-window in windows.c via glfwSetKeyCallback ↓
cross-refs:modules/input.h:? modules/windows.c:?
func
cbMouseButton
→ void
line 128
// ↓ glfw mouse button callback; registered per-window via glfwSetMouseButtonCallback ↓ | ↓ button codes match GLFW_MOUSE_BUTTON_* and the MOUSE enum exposed to Lua ↓
cross-refs:modules/input.h:? modules/windows.c:?
func
inputInit
→ int
line 143
cross-refs:vanir.c:? modules/input.h:?
modules/input.h
Externs
extern
keyPress
struct hook keyPress
line 18
extern
keyRelease
struct hook keyRelease
line 19
extern
inputPressed
struct hook inputPressed
line 20
extern
inputReleased
struct hook inputReleased
line 21
Macros
#define
VANIR
_INPUT_H
line 2
#define
keyBitmask
0x80
line 8
modules/memory.c
Functions
Lua
lua
parse_u64
→ static int
line 22
// ↓ helpers — safe numeric parsing ↓ | ↓ parse unsigned 64-bit from lua (number or string) ↓
↓ fast path: number ↓
if (lua_isnumber(L, idx)) {
*out = (uint64_t)lua_tointeger(L, idx);
return 1;
}↓ string path ↓
const char *s = luaL_checkstring(L, idx);
char *end;
errno = 0;↓ no digits ↓
if (s == end)
return luaL_error(L, "invalid uint64 string (no digits)");↓ trailing garbage ↓
if (*end != '\0')
return luaL_error(L, "invalid uint64 string (trailing characters)");↓ overflow ↓
if (errno == ERANGE)
return luaL_error(L, "uint64 overflow");
lua
parse_i64
→ static int
line 53
// ↓ parse signed 64-bit from lua (number or string) ↓
↓ fast path: number ↓
if (lua_isnumber(L, idx)) {
*out = (int64_t)lua_tointeger(L, idx);
return 1;
}↓ string path ↓
const char *s = luaL_checkstring(L, idx);
char *end;
errno = 0;↓ no digits ↓
if (s == end)
return luaL_error(L, "invalid int64 string (no digits)");↓ trailing garbage ↓
if (*end != '\0')
return luaL_error(L, "invalid int64 string (trailing characters)");↓ overflow ↓
if (errno == ERANGE)
return luaL_error(L, "int64 overflow");
lua
memReadString
(integer arg2)
line 188
// ↓ memory.readString(addr, len) → string ↓
Lua stack args
2integerarg2
lua
memReadBytes
(integer arg2)
line 198
// ↓ memory.readBytes(addr, count) → string (raw bytes) ↓
Lua stack args
2integerarg2
lua
memWriteByte
(integer arg2)
line 210
// ↓ write helpers ↓ | ↓ memory.writeByte(addr, value) ↓
Lua stack args
2integerarg2
lua
memWriteShort
(integer arg2)
line 220
// ↓ memory.writeShort(addr, value) ↓
Lua stack args
2integerarg2
lua
memWriteUShort
(integer arg2)
line 229
// ↓ memory.writeUShort(addr, value) ↓
Lua stack args
2integerarg2
lua
memWriteLong
(integer arg2)
line 238
// ↓ memory.writeLong(addr, value) ↓
Lua stack args
2integerarg2
lua
memWriteULong
(integer arg2)
line 247
// ↓ memory.writeULong(addr, value) ↓
Lua stack args
2integerarg2
lua
memWriteFloat
(number arg2)
line 256
// ↓ memory.writeFloat(addr, value) ↓
Lua stack args
2numberarg2
lua
memWriteDouble
(number arg2)
line 265
// ↓ memory.writeDouble(addr, value) ↓
Lua stack args
2numberarg2
lua
memWriteBool
(boolean arg2)
line 296
// ↓ memory.writeBool(addr, value) ↓
Lua stack args
2booleanarg2
lua
memWriteString
(string arg2)
line 305
// ↓ memory.writeString(addr, str) — writes raw bytes, no null terminator ↓
Lua stack args
2stringarg2
lua
memGetAddr
(string arg1)
line 321
// ↓ memory.getAddr(str) → integer — address of a lua string's internal buffer ↓ | ↓ useful for testing; don't hold across GC ↓
Lua stack args
1stringarg1
lua
memToHex
(integer arg1)
line 332
// ↓ memory.toHex(addr) → string — format address as hex string ↓
Lua stack args
1integerarg1
lua
memProtect
(integer arg2, integer arg3)
line 344
// ↓ memory.protect(addr, size, prot) — change memory protection flags (windows) ↓
Lua stack args
2integerarg2
3integerarg3
C Internal
func
memReadByte
→ static int
line 87
// ↓ read helpers — each returns 1 value or errors ↓ | ↓ memory.readByte(addr) → number ↓
func
memReadShort
→ static int
line 96
// ↓ memory.readShort(addr) → number (Int16) ↓
func
memReadUShort
→ static int
line 106
// ↓ memory.readUShort(addr) → number (UInt16) ↓
func
memReadLong
→ static int
line 116
// ↓ memory.readLong(addr) → number (Int32) ↓
func
memReadULong
→ static int
line 126
// ↓ memory.readULong(addr) → number (UInt32) ↓
func
memReadFloat
→ static int
line 136
// ↓ memory.readFloat(addr) → number (Float32) ↓
func
memReadDouble
→ static int
line 146
// ↓ memory.readDouble(addr) → number (Float64) ↓
func
memReadInt64
→ static int
line 156
// ↓ memory.readInt64(addr) → string (because lua integers may be 32-bit on some builds) ↓
func
memReadUInt64
→ static int
line 166
// ↓ memory.readUInt64(addr) → string (decimal) to avoid sign loss ↓
func
memReadBool
→ static int
line 178
// ↓ memory.readBool(addr) → boolean ↓
func
memWriteInt64
→ static int
line 274
// ↓ memory.writeInt64(addr, value|string) ↓
func
memWriteUInt64
→ static int
line 285
// ↓ memory.writeUInt64(addr, value|string) ↓
func
memWriteBytes
→ static int
line 315
// ↓ memory.writeBytes(addr, str) — alias for writeString ↓
func
memPageConstants
→ static int
line 357
// ↓ windows memory page protection constants ↓
func
memoryInit
→ int
line 412
cross-refs:vanir.c:? modules/memory.h:?
modules/memory.h
Macros
#define
VANIR
_MEMORY_H
line 2
modules/render.c
Functions
Lua
lua
selectRender
(userdata arg1)
line 80
// window methods ↓↓↓ window methods ///
Targets this window for subsequent draw calls. Must be called before any render.* functions in a frame. Internally opens a WebGPU render pass with LoadOp_Load so previous contents are preserved.
Lua stack args
1userdataarg1
→returnNothing pushed to the Lua stack; errors via luaL_error on bad input.
↓ grab next texture from the swapchain ↓
WGPUSurfaceTexture surf_tex = {0};
wgpuSurfaceGetCurrentTexture(w->surface, &surf_tex);↓ create a view into the swapchain for this frame
w->frame.texture = surf_tex.texture;
w->frame.view = wgpuTextureCreateView(w->frame.texture, NULL);↓ open command encoder; all gpu commands for this frame go through here ↓
WGPUCommandEncoderDescriptor enc_desc = {0};
w->frame.encoder = wgpuDeviceCreateCommandEncoder(gpu.device, &enc_desc);↓ push updated viewport to uniform buffer ↓
struct Pipeline *p = w->pipeline;
if (p && p->uniformBuffer) {
float vp[2] = { (float)w->fbWidth, (float)w->fbHeight };↓ open initial pass with LoadOp_Load; but dont clear ↓
beginPass(w, WGPULoadOp_Load);
cross-refs:graphics/rendertarget.c:? modules/render.h:? modules/windows.c:? modules/windows.h:?
lua
stopRender
(userdata arg1)
line 178
Closes the current render pass and finalises the frame for the targeted window. Pairs with selectRender. Flushes any pending CPU-side vertex batches before closing.
Lua stack args
1userdataarg1
↓ closes initial geometry pass ↓
endPass(w);
↓ if there are batched draw commands, open a second pass and flush them ↓
↓ batched geometry is submitted in a separate pass so it draws on top of ↓
struct Pipeline *p = w->pipeline;
if (p && p->cmdCount > 0) {
beginPass(w, WGPULoadOp_Load);
flushBatches(w);
endPass(w);
}↓ Finish encoding and submit ↓
WGPUCommandBufferDescriptor cmd_desc = {0};
WGPUCommandBuffer cmd = wgpuCommandEncoderFinish(w->frame.encoder, &cmd_desc);↓ submit everything to gpu ↓
wgpuQueueSubmit(gpu.queue, 1, &cmd);
vanir_log_info("stopRender: submitted command buffer for \"%s\"", w->name);↓ frame.view / frame.texture stay alive until update() presents the frame. ↓
cross-refs:graphics/draw.c:? modules/render.h:? modules/windows.c:? modules/windows.h:?
lua
update
(userdata arg1)
line 233
// ↓ presents completed frame, then releases texture and view; if stopRender not called: disrecards ↓
Presents the completed frame to the screen (calls wgpuSurfacePresent), then polls GLFW events and fires pending hooks. The main loop calls this once per iteration.
Lua stack args
1userdataarg1
↓ called without a pending frame — silent no-op (minimized window) ↓
if (!w->frame.pending)
return 0;↓ stopRender never called, present would submit against texture and panic so we discard ↓
if (w->frame.encoder) {
throw("update", w->name,
"stopRender was not called before update — frame discarded");
endPass(w);
wgpuCommandEncoderRelease(w->frame.encoder);↓ window was destroyed between selectRender and update; surface is gone ↓
if (!w->surface) {
vanir_log_info("update: window \"%s\" already destroyed, skipping present", w->name);↓ wgpu-native can panic on invalid state, so WGPU_GUARD wraps the call to only longjmp back ↓
wgpuSurfacePresent(w->surface);
↓ release resources after presenting ↓
if (w->frame.view) {
wgpuTextureViewRelease(w->frame.view);cross-refs:graphics/rendertarget.c:? modules/render.h:? modules/timer.c:? modules/windows.c:? modules/windows.h:? types/texture.c:?
lua
destroy
(userdata arg1)
line 301
// ↓ releases pipeline resources for a window ↓
Lua stack args
1userdataarg1
cross-refs:vanir.c:? graphics/rendertarget.h:? graphics/shader.h:? graphics/textures.h:?
lua
colorFromTable
→ static void
line 324
// ↓ read color from a lua table at stack index idx (r,g,b,a fields, 0-255) ↓
lua
setTexture
(nil arg1)
line 341
Lua stack args
1nilarg1
cross-refs:graphics/rendertarget.h:? graphics/textures.c:? modules/render.h:?
lua
setBlend
(integer source, integer blend)
line 356
// ↑ active color cached in C; render.setColor writes here, draw calls read directly ↑
Lua stack args
1integersource
2integerblend
TODO(webgpu): rebuild pipeline with new blend factors.
cross-refs:modules/render.h:?
lua
enable
(integer cap)
line 365
Lua stack args
1integercap
TODO(webgpu): map cap to the appropriate pipeline field.
cross-refs:modules/render.h:? modules/windows.c:?
lua
disable
(integer cap)
line 373
Lua stack args
1integercap
cross-refs:modules/render.h:? modules/windows.c:?
lua
clear
(nil? arg1)
line 383
// ↓ closes current pass and opens new one; clear color is applied as pass load action ↓ | render.clear([Color or nil clr, boolean or nil clearDepth, boolean or nil clearStencil]) | clearDepth / clearStencil are accepted for API compatibility but are no-ops in this 2D WebGPU pipeline
Clears the current render target to the window's stored clear colour. Closes the active pass and reopens it with LoadOp_Clear, so everything drawn after this call is on a blank background.
Lua stack args
1nil?arg1
default: reuse last clear color
struct color color = w->clearColor;
cross-refs:graphics/rendertarget.c:? modules/render.h:?
lua
clearRGBA
(number arg1, number arg2, number arg3, number arg4)
line 410
// render.clearRGBA(number r, number g, number b, number a [, boolean clearDepth, boolean clearStencil]) | Like render.clear() but takes raw 0-255 component values instead of a Color table
Lua stack args
1numberarg1
2numberarg2
3numberarg3
4numberarg4
args 5/6: clearDepth, clearStencil — no-op
struct color color;
color.r = (float)luaL_checknumber(L, 1) / 255.0f;
color.g = (float)luaL_checknumber(L, 2) / 255.0f;
color.b = (float)luaL_checknumber(L, 3) / 255.0f;
color.a = (float)luaL_checknumber(L, 4) / 255.0f;cross-refs:modules/render.h:?
lua
renderTargetExists
(string name)
line 467
// render.renderTargetExists(string name) → boolean
Lua stack args
1stringname
cross-refs:modules/render.h:?
lua
destroyRenderTarget
(string name)
line 483
// render.destroyRenderTarget(string name) | Looks up the render target by name, releases all GPU resources, and removes it from the pool
Lua stack args
1stringname
↓ compact the pool: swap with last entry ↓
rtPool.targets[i] = rtPool.targets[--rtPool.count];
rtPool.targets[rtPool.count] = NULL;cross-refs:modules/render.h:?
lua
begin
(integer arg1)
line 517
Lua stack args
1integerarg1
lua
pushMatrix
(nil? arg1)
line 549
// render.pushMatrix([mat]) ↓ | ↓ saves the current matrix, optionally sets a new one ↓ | ↓ if mat is given: push current → set current = mat ↓ | ↓ if no arg: just push current (save slot for a later popMatrix) ↓
Lua stack args
1nil?arg1
↓ save current onto stack ↓
memcpy(matrixStack[matrixStackTop], activeMatrix, sizeof(activeMatrix));
matrixStackTop++;↓ if a Matrix table was passed, load it as the new active matrix ↓
if (!lua_isnoneornil(L, 1)) {
matrixGet(L, 1, activeMatrix);
matrixCheckIdentity();
lua
setMatrix
(table arg1)
line 605
// render.setMatrix(mat) ↓
Lua stack args
1tablearg1
lua
scissor
(number arg1, number arg2, number arg3, number arg4)
line 635
Lua stack args
1numberarg1
2numberarg2
3numberarg3
4numberarg4
lua
setViewport
(number arg1, number arg2, number arg3, number arg4)
line 655
// ↓ set gpu viewport rect in pixel coords; resets scissor to full viewport ↓
Lua stack args
1numberarg1
2numberarg2
3numberarg3
4numberarg4
↓ minDepth / maxDepth standard NDC range ↓
wgpuRenderPassEncoderSetViewport(w->frame.passEncoder, x, y, vw, vh, 0.0f, 1.0f);
↓ also update the viewport uniform so pixel->NDC conversion stays correct ↓
struct Pipeline *p = w->pipeline;
cross-refs:modules/render.h:?
C Internal
func
beginPass
→ static void
line 28
// ↓ render passes are a contiguous block of draw commands ↓ | ↓ selectRender opens one with LoadOp_Load (preserve previous contents), clear() closes and reopens with LoadOp_Clear using color ↓
↓ if a custom shader is active, use it; otherwise use the built-in pipeline ↓
if (w->frame.passEncoder && p) {
WGPURenderPipeline activePipeline = p->pipeline;cross-refs:graphics/shader.h:?
func
endPass
→ static void
line 70
// ↓ stopRender closes the pass, then flushBatches opens another to upload and draw cpu batch ↓
func
getGlobalColor
→ void
line 332
// ↓ draw calls call this; direct struct copy, zero lua overhead ↓
cross-refs:graphics/draw.c:? modules/render.h:?
func
setColor
→ int
line 335
Sets the active draw colour used by all subsequent shape-drawing calls until changed again. Colour values are floats in the range 0–255 as in the rest of Vanir's colour API.
Parameters
lua_State *LLua state. Expects a Color table at stack index 1.
cross-refs:modules/render.h:?
func
clearDepth
→ int
line 406
// render.clearDepth([boolean or nil clearStencil]) | No depth attachment in this 2D WebGPU pipeline — no-op stub
cross-refs:modules/render.h:?
func
depthRange
→ int
line 435
// render.depthRange(number min, number max) | WebGPU depth is fixed-range NDC 0..1; not user-configurable in this pipeline — no-op
cross-refs:modules/render.h:?
func
enableDepth
→ int
line 439
// render.enableDepth(boolean enable) | No depth buffer in this 2D pipeline — no-op stub
cross-refs:modules/render.h:?
func
pushCustomClipPlane
→ int
line 443
// render.pushCustomClipPlane(Vector normal, number distance) | WebGPU has no clip plane API — no-op stub
cross-refs:modules/render.h:?
func
popCustomClipPlane
→ int
line 446
// render.popCustomClipPlane()
cross-refs:modules/render.h:?
func
renderViewsLeft
→ int
line 450
// render.renderViewsLeft() → number | This engine renders one view per frame; returns 1 for compatibility
cross-refs:modules/render.h:?
func
readPixel
→ int
line 457
// render.readPixel(number x, number y) → r, g, b, a | WebGPU GPU readback requires async buffer mapping — returns 0,0,0,0 as stub
cross-refs:modules/render.h:?
func
force
→ int
line 516
// stubs ↓↓↓ stubs
func
end
→ int
line 518
cross-refs:modules/files.c:? modules/memory.c:?
func
matrixCheckIdentity
→ static void
line 530
// static int matrixStackTop = 0; /* ↓ number of saved matrices ↓ | static float activeMatrix[9]; /* ↓ current transform applied to all verts ↓ | static bool matrixIsIdentity = true; /* ↓ fast path: skip transform when identity ↓
func
matrixStackInit
→ static void
line 539
// ↓ called once on module load ↓
func
popMatrix
→ int
line 575
// render.popMatrix() ↓
func
resetMatrix
→ int
line 593
// render.resetMatrix() ↓
func
getMatrix
→ static int
line 618
// render.getMatrix() → Matrix ↓
func
applyActiveMatrix
→ void
line 624
// ↓ apply the active matrix to a point in-place; called by pushVert in draw.c ↓
cross-refs:graphics/draw.c:? modules/render.h:?
func
resetViewport
→ int
line 683
// ↓ reset viewport to the full framebuffer ↓
cross-refs:modules/render.h:?
func
setQuality
→ int
line 702
cross-refs:modules/render.h:?
func
renderInit
→ int
line 773
cross-refs:vanir.c:? modules/render.h:?
Externs
extern
gpu
struct VanirGPU gpu
line 16
extern
activeShader
struct Shader *activeShader
line 19
// ↓ activeShader is owned by graphics/shader.c; NULL means use the built-in pipeline ↓
Macros
#define
MATRIX
_STACK_MAX 64
line 524
// TODO: fix this mess later, its horrible | ↓ the active matrix is applied to every vertex pushed by draw calls ↓ | ↓ a stack lets you save/restore it across scopes with push/pop ↓
modules/render.h
Externs
extern
activeColor
struct color activeColor
line 38
// ↓ active color; written by render.setColor, read directly by draw calls ↓
extern
activeTexture
struct Texture *activeTexture
line 41
// ↓ active texture; written by render.setTexture, read by textured draw calls ↓
extern
currentRenderWindow
struct glfwWindow *currentRenderWindow
line 43
modules/system.c
Functions
Lua
lua
getScreenSize
(integer? arg1)
line 142
// ↓ primary monitor resolution shorthand ↓
Lua stack args
1integer?arg1
↓ 1-indexed from lua ↓
int count;
GLFWmonitor **monitors = glfwGetMonitors(&count);
int idx = (int)luaL_optinteger(L, 1, 1) - 1;cross-refs:modules/system.h:?
lua
setClipboard
(string text)
line 168
Lua stack args
1stringtext
cross-refs:modules/system.h:?
lua
getEnv
(string key)
line 185
// ↓ environment variable ↓
Lua stack args
1stringkey
cross-refs:modules/system.h:?
lua
systemSleep
(integer ms)
line 260
// ↓ suspend the calling thread for ms milliseconds ↓
Suspends the calling thread for the given number of milliseconds. Uses Sleep() on Windows and nanosleep() on POSIX. Blocks the entire thread — do not call inside a render hook unless you want to cap your frame rate.
Lua stack args
1integermsinteger — milliseconds to sleep (clamped to 0 if negative).
cross-refs:modules/system.h:?
lua
systemExit
(integer? arg1)
line 280
// ↓ terminate the process cleanly with the given exit code ↓
Terminates the process immediately with the given exit code. Skips Vanir's normal shutdown sequence; prefer quit() for a clean shutdown.
Lua stack args
1integer?arg1
unreachable
return 0;
cross-refs:modules/system.h:?
⚠ This function never returns.
C Internal
func
getUsername
→ int
line 22
// ↓ current logged-in username ↓
cross-refs:modules/system.h:?
func
getOS
→ int
line 49
// ↓ OS name string ↓
cross-refs:modules/system.h:?
func
getSystemInfo
→ int
line 64
// ↓ kernel/system info table: { sysname, nodename, release, version, machine } ↓
cross-refs:modules/system.h:?
func
getMonitorCount
→ int
line 110
// ↓ monitor count ↓
cross-refs:modules/system.h:?
func
getMonitors
→ int
line 120
// ↓ monitor info table array; { width, height, refreshRate, name } per entry ↓
cross-refs:modules/system.h:?
func
getClipboard
→ int
line 158
// ↓ clipboard read / write ↓
cross-refs:modules/system.h:?
func
getTime
→ int
line 178
// ↓ wall clock time in seconds (double) ↓
cross-refs:modules/system.h:?
func
getCPUCount
→ int
line 198
// ↓ logical CPU count ↓
Returns the number of logical processors (hardware threads) available to the process. Uses GetSystemInfo on Windows and sysconf(_SC_NPROCESSORS_ONLN) on Linux/macOS.
Parameters
→returninteger — logical CPU count, always at least 1.
cross-refs:modules/system.h:?
func
getTotalRAM
→ int
line 214
// ↓ total physical RAM in bytes ↓
Returns the total physical RAM installed in the system, in bytes, as a Lua number. Uses GlobalMemoryStatusEx on Windows and sysconf(_SC_PHYS_PAGES × _SC_PAGE_SIZE) on Linux/macOS.
Parameters
→returnnumber (bytes), or nil if the platform call fails.
cross-refs:modules/system.h:?
func
getExecutablePath
→ int
line 235
// ↓ absolute path to the running executable ↓
Returns the absolute path to the currently running executable. Uses GetModuleFileNameA on Windows and readlink("/proc/self/exe") on Linux.
Parameters
→returnstring path, or nil on failure.
cross-refs:modules/system.h:?
func
getLocale
→ int
line 289
// ↓ IETF locale tag for the current user (e.g. "en-US") ↓
Returns the IETF locale tag for the current user, e.g. "en-US" or "fr-FR". Uses GetUserDefaultLocaleName on Windows and setlocale/LANG on POSIX.
Parameters
→returnstring locale tag.
cross-refs:modules/system.h:?
func
systemInit
→ int
line 341
cross-refs:vanir.c:? modules/system.h:?
modules/system.h
modules/testfunc.c
Functions
Lua
lua
l_test
(string? msg)
line 38
Lua stack args
1string?msg
cross-refs:vanir.c:? modules/testfunc.h:?
C Internal
func
show_alert
→ static void
line 10
func
show_alert
→ static void
line 17
modules/testfunc.h
Externs
extern
activeWindow
struct glfwWindow *activeWindow
line 8
modules/timer.c
Structs
struct
Timer
line 16
// ↓ per-timer state ↓
// ms between fires// -1 = infinite// lua registry ref for the callback// absolute ms timestamp for next fire// realtime() when paused; negative means not paused
Functions
Lua
lua
tickTimers
→ void
line 123
// ↓ tick all active timers; called from the think hook or manually ↓
↓ update frametime ↓
if (lastFrameTime > 0.0)
frameDelta = now - lastFrameTime;↓ advance by delay rather than snapping to now; avoids drift ↓
t->nextFire += t->delay;
↓ if we fell very far behind (e.g. paused), skip to current ↓
if (t->nextFire < now)
t->nextFire = now + t->delay;↓ call the lua function ↓
if (t->funcRef != LUA_NOREF) {
lua_rawgeti(L, LUA_REGISTRYINDEX, t->funcRef);↓ count down reps ↓
if (t->reps >= 0) {
t->repsLeft -= 1;cross-refs:modules/hooks.c:? modules/timer.h:?
lua
timerCreate
(string name, number delay, integer arg3, function arg4)
line 203
// ↓ timer.create(name, delay, reps, func) → None ↓
Lua stack args
1stringname
2numberdelay
3integerarg3
4functionarg4
-1 for inf
const char *name = luaL_checkstring(L, 1);
double delay = luaL_checknumber(L, 2);
int reps = (int)luaL_checkinteger(L, 3);↓ replace existing timer with same name ↓
struct Timer *t = findTimer(name);
lua
timerSimple
(number delay, function arg2)
line 239
// ↓ timer.simple(delay, func) → None — one-shot anonymous timer ↓
Lua stack args
1numberdelay
2functionarg2
name, delay, func
lua_pushstring(L, name);
lua_insert(L, 1);name, delay, func, 1
lua_pushinteger(L, 1);
name, delay, 1, func
lua_insert(L, 3);
lua
timerRemove
(string name)
line 257
// ↓ timer.remove(name) → None ↓
Lua stack args
1stringname
lua
timerExists
(string name)
line 271
// ↓ timer.exists(name) → boolean ↓
Lua stack args
1stringname
lua
timerStart
(string name)
line 280
// ↓ timer.start(name) → boolean — restart a stopped/finished timer from now ↓
Lua stack args
1stringname
lua
timerStop
(string name)
line 300
// ↓ timer.stop(name) → boolean — stops (deactivates) a timer without removing it ↓
Lua stack args
1stringname
lua
timerPause
(string name)
line 318
// ↓ timer.pause(name) → boolean ↓
Lua stack args
1stringname
lua
timerUnpause
(string name)
line 337
// ↓ timer.unpause(name) → boolean ↓
Lua stack args
1stringname
↓ push nextFire forward by the time spent paused ↓
double pausedFor = nowMs() - t->pausedAt;
lua
timerToggle
(string name)
line 360
// ↓ timer.toggle(name) → boolean — current paused state after toggle ↓
Lua stack args
1stringname
now unpaused
if (t->paused) {
lua_settop(L, 1);
timerUnpause(L);
lua_pushboolean(L, 0);
} else {
lua_settop(L, 1);
timerPause(L);now paused
} else {
lua_settop(L, 1);
timerPause(L);
lua_pushboolean(L, 1);
}
lua
timerAdjust
(string name, number delay, integer arg3, nil arg4)
line 384
// ↓ timer.adjust(name, delay, reps|nil, func|nil) → boolean ↓
Lua stack args
1stringname
2numberdelay
3integerarg3
4nilarg4
lua
timerTimeleft
(string name)
line 412
// ↓ timer.timeleft(name) → number (negative if paused) | nil ↓
Lua stack args
1stringname
↓ return negative to indicate paused; magnitude is remaining ms ↓
if (t->paused) {
left = -(t->nextFire - t->pausedAt);
} else {
left = t->nextFire - nowMs();
}
lua
timerRepsleft
(string name)
line 437
// ↓ timer.repsleft(name) → number | nil ↓
Lua stack args
1stringname
C Internal
func
rawMilliseconds
→ static int64_t
line 42
func
nowMs
→ static double
line 59
func
nowSec
→ static double
line 65
// ↓ systime — unix epoch in seconds, float ↓
↓ windows epoch is 1601-01-01; unix is 1970-01-01; delta = 116444736000000000 100ns ticks ↓
return (double)(uli.QuadPart - 116444736000000000ULL) / 10000000.0;
#else
struct timespec ts;
func
realtime
→ int
line 172
// ↓ realtime() → number — monotonic ms since process start ↓
func
systime
→ int
line 179
// ↓ systime() → number — unix epoch seconds as float ↓
func
curtime
→ int
line 186
// ↓ curtime() → number — seconds since vanirInit ↓
func
frametime
→ int
line 196
// ↓ frametime() → number — ms of the last frame ↓
func
timerGetTimersLeft
→ int
line 449
// ↓ timer.getTimersLeft() → number — count of active, unfinished timers ↓
func
timerInit
→ int
line 483
cross-refs:vanir.c:? modules/timer.h:?
modules/timer.h
modules/windows.c
Functions
Lua
lua
isHovering
(userdata arg1)
line 313
// window metafunctions ↓↓↓ window metafunctions
Lua stack args
1userdataarg1
lua
isFocused
(userdata arg1)
line 320
Lua stack args
1userdataarg1
lua
getTitle
(userdata arg1)
line 328
Lua stack args
1userdataarg1
lua
getID
(userdata arg1)
line 336
Lua stack args
1userdataarg1
lua
getMouse
(userdata arg1)
line 346
// ↓ returns nil, nil if mouse is off window ↓
Lua stack args
1userdataarg1
lua
getSize
(userdata arg1)
line 367
// ↓ returns screen coords, not framebuffer pixels; uses fbWidth/fbHeight internally for gpu operations ↓ | ↓ when minimized, glfw reports 0x0 so we return the last known size instead ↓
Lua stack args
1userdataarg1
cross-refs:graphics/textures.c:? modules/font.c:? modules/windows.h:? types/texture.c:?
lua
getMonitorIndex
(userdata arg1)
line 375
Lua stack args
1userdataarg1
lua
setTitle
(userdata arg1, string title)
line 398
// ↓ set window title at runtime ↓
Lua stack args
1userdataarg1
2stringtitle
lua
setPos
(userdata arg1, integer x, integer y)
line 409
// ↓ move window to screen position ↓
Lua stack args
1userdataarg1
2integerx
3integery
lua
getPos
(userdata arg1)
line 422
// ↓ get window screen position ↓
Lua stack args
1userdataarg1
lua
setSize
(userdata arg1, integer width, integer height)
line 434
// ↓ resize window ↓
Lua stack args
1userdataarg1
2integerwidth
3integerheight
lua
setIcon
(userdata arg1, integer width, integer height, string pixels)
line 445
// ↓ set window icon from raw RGBA pixels. pass nil to reset to default ↓
Lua stack args
1userdataarg1
2integerwidth
3integerheight
4stringpixels
↓ expects raw RGBA bytes, width * height * 4 ↓
if (len < (size_t)(width * height * 4)) {
throw("setIcon", (*w)->name, "pixel data too short for given dimensions");
lua
setOpacity
(userdata arg1, number arg2)
line 474
// ↓ set window opacity (0.0 - 1.0) ↓
Lua stack args
1userdataarg1
2numberarg2
lua
setAlwaysOnTop
(userdata arg1, boolean ontop)
line 484
// ↓ toggle always-on-top / floating hint ↓
Lua stack args
1userdataarg1
2booleanontop
lua
setFullscreen
(userdata arg1, boolean enabled, integer? arg3)
line 494
// ↓ enter / leave fullscreen on monitor index (default 0). pass false to exit ↓
Lua stack args
1userdataarg1
2booleanenabled
3integer?arg3
↓ save windowed state for restore later ↓
glfwGetWindowPos((*w)->window, &(*w)->x, &(*w)->y);
↓ restore to last saved windowed position and size ↓
glfwSetWindowMonitor((*w)->window, mon, 0, 0, mode->width, mode->height, mode->refreshRate);
} else {
glfwSetWindowMonitor((*w)->window, NULL, (*w)->x, (*w)->y, (*w)->width, (*w)->height, 0);
}
lua
focus
(userdata arg1)
line 521
// ↓ focus (raise) the window ↓
Lua stack args
1userdataarg1
lua
minimize
(userdata arg1, boolean iconify)
line 530
// ↓ minimize/iconify or restore ↓
Lua stack args
1userdataarg1
2booleaniconify
lua
setDecorated
(userdata arg1, boolean decorated)
line 540
// ↓ show / hide window decorations (title bar, border) ↓
Lua stack args
1userdataarg1
2booleandecorated
lua
setResizable
(userdata arg1, boolean resizable)
line 550
// ↓ enable / disable user resize ↓
Lua stack args
1userdataarg1
2booleanresizable
lua
setAspectRatio
(userdata arg1, integer numer, integer denom)
line 560
// ↓ lock aspect ratio; pass nil, nil to disable ↓
Lua stack args
1userdataarg1
2integernumer
3integerdenom
lua
setSizeLimits
(userdata arg1, integer minW, integer minH, integer maxW, integer maxH)
line 578
// ↓ clamp window size between min and max; pass nil for unconstrained ↓
Lua stack args
1userdataarg1
2integerminW
3integerminH
4integermaxW
5integermaxH
lua
setCursorMode
(userdata arg1, integer mode)
line 591
// ↓ set cursor mode: CURSOR_NORMAL / CURSOR_HIDDEN / CURSOR_DISABLED ↓
Lua stack args
1userdataarg1
2integermode
lua
setCursorShape
(userdata arg1, integer shape)
line 601
// ↓ set cursor to a standard shape (CURSOR_SHAPE enum) ↓
Lua stack args
1userdataarg1
2integershape
lua
resetCursor
(userdata arg1)
line 619
// ↓ reset to default arrow cursor ↓
Lua stack args
1userdataarg1
lua
requestAttention
(userdata arg1)
line 628
// ↓ flash the window taskbar entry to grab attention ↓
Lua stack args
1userdataarg1
lua
restore
(userdata arg1)
line 637
// ↓ restore an iconified or maximized window back to normal ↓
Lua stack args
1userdataarg1
cross-refs:graphics/rendertarget.c:? graphics/shader.c:? modules/render.c:?
lua
maximize
(userdata arg1)
line 646
// ↓ maximize window to fill monitor work area ↓
Lua stack args
1userdataarg1
lua
setVisible
(userdata arg1, boolean visible)
line 655
// ↓ show / hide a window without destroying it ↓
Lua stack args
1userdataarg1
2booleanvisible
lua
setRawMouse
(userdata arg1, boolean enabled)
line 666
// ↓ check if raw mouse motion is supported and toggle it ↓
Lua stack args
1userdataarg1
2booleanenabled
lua
createWindow
(integer? x, integer? y, integer? width, integer? height, string? name)
line 1195
// ↓ lua interface for internal newWindow ↓
Lua stack args
1integer?x
2integer?y
3integer?width
4integer?height
5string?name
↓ push userdata before calling so window is reachable by gc ↓
struct glfwWindow **udata = (struct glfwWindow **)lua_newuserdata(L, sizeof(struct glfwWindow *));
*udata = window;↓ main sauce ↓
newWindow(window);
↓ allocate callbacks for event hooks ↓
onHoverChange.callback = createCallback(sizeof(bool), lua_bool);
onFocusChange.callback = createCallback(sizeof(bool), lua_bool);
onEvent.callback = createCallback(sizeof(int), integer);
onOpen.status = hook_awaiting;cross-refs:graphics/rendertarget.c:? graphics/shader.c:? graphics/textures.c:? modules/windows.h:?
C Internal
func
on_adapter
→ static void
line 35
// ↓ webgpu async callbacks ↓
TODO: maybe change this later
if (status == WGPURequestAdapterStatus_Success) *(WGPUAdapter *)ud1 = a;
func
on_device
→ static void
line 38
func
vanirGPUInit
→ bool
line 45
// ↑ webgpu async callbacks ↑ | ↓ shared gpu init not used; however, here for explicit init if needed ↓
cross-refs:modules/windows.h:?
func
vanirGPUDestroy
→ void
line 98
// ↓ release shared gpu context resources; called automatnically when all windows close ↓
Releases the shared WebGPU device, adapter, and instance in that order. Must be called after all windows and pipelines have been destroyed; calling it earlier causes use-after-free crashes in the WebGPU backend.
// ↑ perhaps make a marco for these checks later ↑
cross-refs:vanir.c:? modules/windows.h:?
⚠ This is called automatically by quit(). Do not call it directly.
func
cbResize
→ static void
line 135
func
cbCursorEnter
→ static void
line 172
func
cbFocus
→ static void
line 184
func
cbClose
→ static void
line 198
// ↓ marks for deferred free; cleanup happens next frame ↓
func
releaseFrame
→ void
line 214
// glfw callbacks ↑↑↑ glfw callbacks | ↓ frame release ↓
cross-refs:vanir.c:? modules/render.c:? modules/windows.h:?
func
destroyPipeline
→ void
line 245
// ↑ frame release ↑ | ↓ pipeline lifecycle ↓
// ↑ kind of unholy ↑
cross-refs:vanir.c:? modules/render.c:? modules/windows.h:?
func
destroyWindowResources
→ static void
line 261
↓ tear down the shared GPU context when the last window is gone ↓
if (windowPool.count == 1)
vanirGPUDestroy();
func
renderHandle
→ void
line 284
// ↑ pipeline lifecycle ↑ | ↓ render hook handle ↓
↓ deferred window freeing ↓
for (size_t i = 0; i < windowPool.count; ) {
struct glfwWindow *w = windowPool.windows[i];↓ shift remaining windows down to fill gap ↓
for (size_t j = i; j < windowPool.count - 1; ++j)
windowPool.windows[j] = windowPool.windows[j + 1];
func
buildRenderPipeline
→ static WGPURenderPipeline
line 704
// ↑ converts pixel-space -> NOC using viewport uniform (width / height); used by all draw calls ↑ | ↓ called twice for triangles & lines; builds single WGPURenderPipeline for primitive topology and blend ↓
↓ vertex buffer layout; slot 0, stride 7 floats, 2 attributes ↓
WGPUVertexAttribute attrs[2] = {0};
attrs[0].format = WGPUVertexFormat_Float32x3;
attrs[0].offset = 0;
attrs[0].shaderLocation = 0;
attrs[1].format = WGPUVertexFormat_Float32x4;
attrs[1].offset = 3*sizeof(float);
attrs[1].shaderLocation = 1;↓ alpha blending; output = src * srcFactor + dst * dstFactor ↓
WGPUBlendState blend = {0};
blend.color.srcFactor = blendSrc;
blend.color.dstFactor = blendDst;
blend.color.operation = WGPUBlendOperation_Add;
blend.alpha.srcFactor = WGPUBlendFactor_One;
blend.alpha.dstFactor = WGPUBlendFactor_OneMinusSrcAlpha;
blend.alpha.operation = WGPUBlendOperation_Add;↓ pipeline layout and shader are referecne-counted; release after ownership transfer ↓
wgpuPipelineLayoutRelease(pl);
wgpuShaderModuleRelease(shader);
func
buildTexturedPipeline
→ static WGPURenderPipeline
line 811
// ↓ pos(xyzw) + uv(uv) = 6 floats per vertex — matches TEXTURED_VERTEX_STRIDE in windows.h ↓ | ↓ build the textured pipeline with two bind group layouts ↓
↓ vertex layout: location0 = pos (xyzw), location1 = uv (xy) ↓
WGPUVertexAttribute attrs[2] = {0};
attrs[0].format = WGPUVertexFormat_Float32x4;
attrs[0].offset = 0;
attrs[0].shaderLocation = 0;
attrs[1].format = WGPUVertexFormat_Float32x2;
attrs[1].offset = 4 * sizeof(float);
attrs[1].shaderLocation = 1;
func
newWindow
→ static void
line 1003
// pipeline / shader ↑↑↑ pipeline / shader | ↓ window creation; glfw -> webgpu surface. on first call, init shared gpu context (instance -> adapter -> device -> queue) ↓
↓ glfw event callback reg ↓
glfwSetWindowPos(window->window, window->x, window->y);
glfwSetFramebufferSizeCallback(window->window, cbResize);
glfwSetCursorEnterCallback(window->window, cbCursorEnter);
glfwSetWindowFocusCallback(window->window, cbFocus);
glfwSetWindowCloseCallback(window->window, cbClose);
glfwSetKeyCallback(window->window, cbKey);
glfwSetMouseButtonCallback(window->window, cbMouseButton);
glfwGetWindowSize(window->window, &window->width, &window->height);
glfwGetFramebufferSize(window->window, &window->fbWidth, &window->fbHeight);↓ lazy gpu init: create the instance on the first window only ↓
if (!gpu.instance) {
WGPUInstanceDescriptor inst_desc = {0};
gpu.instance = wgpuCreateInstance(&inst_desc);↓ create the platform-specific surface from glfw3webgpu.h ↓
window->surface = glfwGetWGPUSurface(gpu.instance, window->window);
↓ request adapter and device on the first window only ↓
if (!gpu.adapter) {
WGPURequestAdapterOptions adapter_opts = {0};
adapter_opts.compatibleSurface = window->surface;
WGPURequestAdapterCallbackInfo adapter_cb = {0};
adapter_cb.callback = on_adapter;
adapter_cb.userdata1 = &gpu.adapter;↓ query surface for supported formats/modes ↓
WGPUSurfaceCapabilities caps = {0};
wgpuSurfaceGetCapabilities(window->surface, gpu.adapter, &caps);
window->surfaceFormat = caps.formats[0];↓ prefer mailbox (low-latency) > immediate (no vsync) > fifo (vsync) ↓
WGPUPresentMode presentMode = WGPUPresentMode_Fifo;
for (size_t i = 0; i < caps.presentModeCount; ++i) {
if (caps.presentModes[i] == WGPUPresentMode_Mailbox) {
presentMode = WGPUPresentMode_Mailbox;↓ normal webgpu surface config ↓
WGPUSurfaceConfiguration surf_cfg = {0};
surf_cfg.device = gpu.device;
surf_cfg.format = window->surfaceFormat;
surf_cfg.usage = WGPUTextureUsage_RenderAttachment | WGPUTextureUsage_CopyDst;
surf_cfg.width = (uint32_t)window->fbWidth;
surf_cfg.height = (uint32_t)window->fbHeight;
surf_cfg.presentMode = presentMode;↓ triangles + line ↓
window->pipeline = buildPipelines(window, WGPUBlendFactor_SrcAlpha, WGPUBlendFactor_OneMinusSrcAlpha);
func
windowsInit
→ int
line 1249
cross-refs:vanir.c:? modules/windows.h:?
modules/windows.h
Structs
struct
VanirGPU
line 14
// ↓ initialised lazily on first createWindow; torn down when the last window closes ↓
Holds the four shared WebGPU objects that every window borrows: instance, adapter, device, and queue. Initialised lazily on the first createWindow call and torn down by vanirGPUDestroy.
cross-refs:graphics/draw.c:? graphics/rendertarget.c:? graphics/shader.c:? graphics/textures.c:? modules/render.c:? modules/windows.c:?
struct
Frame
line 24
// ↓ temp per-frame resources. created in selectRender, consumed in stopRender/update ↓
Transient per-frame GPU resources created in selectRender and consumed in stopRender/update. Not valid outside an active render pair.
struct
DrawCmd
line 35
cross-refs:graphics/draw.c:?
struct
Pipeline
line 42
// ↓ per-window render state. Multiple pipelines can be created and swapped ↓
GPU rendering state for one window. Contains the three render pipelines (solid triangles, lines, textured quads), the uniform buffer, bind group layouts, and the flat CPU-side vertex + draw-command buffers that are uploaded each frame.
// triangle list// line list// ↓ textured quad pipeline (UV coords, group1 = tex+sampler) ↓// { width_f, height_f }// ↓ group1 layout for textured pipeline ↓// ↓ flat CPU vertex buffer ↓// ↓ draw command list ↓// ↓ gpu vertex buffer ↓
cross-refs:graphics/draw.c:? graphics/shader.c:? modules/render.c:? modules/windows.c:?
struct
glfwWindow
line 70
// ↓ each window owns only its surface and surface format. ↓
Per-window state bundle. Owns the GLFW window handle, the WebGPU surface, the rendering pipeline, per-frame transient resources, and the current clear colour.
// ↓ what Lua sees via getSize() ↓// ↓ physical framebuffer size — used for gpu surface and viewport uniform ↓// ↓ last non-minimized screen size; returned by getSize() when minimized ↓
cross-refs:vanir.c:? graphics/draw.c:? graphics/render.h:? graphics/rendertarget.c:? graphics/shader.c:? graphics/shader.h:? graphics/textures.c:? graphics/textures.h:? modules/render.c:? modules/render.h:? modules/testfunc.h:? modules/windows.c:?
struct
windowPool
line 94
cross-refs:vanir.c:? graphics/rendertarget.c:? graphics/shader.c:? graphics/textures.c:? modules/windows.c:?
Enums
enum
DrawType
line 33
// ↓ records one logical draw call in submission order so later draws appear on top ↓
TRIS
cross-refs:graphics/draw.c:?
Externs
extern
gpu
struct VanirGPU gpu
line 21
extern
currentRenderWindow
struct glfwWindow *currentRenderWindow
line 115
extern
preDrawOpaque
struct hook preDrawOpaque
line 117
extern
postDrawOpaque
struct hook postDrawOpaque
line 118
extern
preDrawTranslucent
struct hook preDrawTranslucent
line 119
extern
postDrawTranslucent
struct hook postDrawTranslucent
line 120
Macros
#define
TEXTURED
_VERTEX_STRIDE 6 // ↓ xyzw + uv ↓
line 111
// ↓ textured draw helpers; implemented in graphics/shader.c ↓
types/angle.c
Functions
Lua
lua
angleIndex
(number arg2)
line 28
// ↓ __index: numeric 1/2/3 → p/y/r, then method table ↓
Lua stack args
2numberarg2
lua
angleMul
(number arg1, number arg2)
line 57
// ↓ __mul: Angle * scalar or scalar * Angle ↓
Lua stack args
1numberarg1
2numberarg2
lua
angleDiv
(number arg2)
line 74
// ↓ __div: Angle / scalar ↓
Lua stack args
2numberarg2
lua
angleGetForward
→ static int
line 137
// ↓ :getForward() → Vector ↓
lua
angleGetRight
→ static int
line 160
// ↓ :getRight() → Vector ↓
lua
angleGetUp
→ static int
line 185
// ↓ :getUp() → Vector ↓
lua
angleRotateAroundAxis
(number arg3)
line 210
// ↓ :rotateAroundAxis(axis_vec, degrees) → new Angle ↓
Lua stack args
3numberarg3
lua
angleRound
(nil? arg2)
line 241
// ↓ :round([decimals]) → new Angle ↓
Lua stack args
2nil?arg2
lua
angleSet
(number arg2, number arg3, number arg4)
line 271
// ↓ :set(p, y, r) — mutates in-place, returns self ↓
Lua stack args
2numberarg2
3numberarg3
4numberarg4
lua
angleSetP
(number arg2)
line 291
// ↓ :setP(v) ↓
Lua stack args
2numberarg2
lua
angleSetY
(number arg2)
line 299
// ↓ :setY(v) ↓
Lua stack args
2numberarg2
lua
angleSetR
(number arg2)
line 307
// ↓ :setR(v) ↓
Lua stack args
2numberarg2
lua
Angle
(number? arg1, number? arg2, number? arg3)
line 345
// ↓ Angle(p, y, r) ↓
Lua stack args
1number?arg1
2number?arg2
3number?arg3
cross-refs:vanir.c:? types/common.h:? types/matrix.c:? types/quaternion.c:?
C Internal
func
pushAngle
→ static void
line 7
func
toStringAngle
→ static int
line 17
// ↓ __tostring ↓
func
angleUnm
→ static int
line 86
// ↓ __unm: -Angle ↓
func
angleEq
→ static int
line 93
// ↓ __eq ↓
func
angleAdd
→ static int
line 104
// ↓ __add ↓
func
angleSub
→ static int
line 115
// ↓ __sub ↓
func
angleIsZero
→ static int
line 126
// ↓ :isZero() ↓
func
angleClone
→ static int
line 264
// ↓ :clone() ↓
func
angleSetZero
→ static int
line 281
// ↓ :setZero() — mutates in-place, returns self ↓
types/color.c
Functions
Lua
lua
colorIndex
(number arg2)
line 28
// ↓ __index: numeric 1/2/3/4 → r/g/b/a, then method table ↓ | ↓ do i really need this ↓
Lua stack args
2numberarg2
lua
colorConcat
→ static int
line 56
// ↓ __concat: Color .. Color or Color .. string ↓
↓ convert both operands to string, concatenate ↓
lua_getglobal(L, "tostring");
lua_pushvalue(L, 1);
lua_call(L, 1, 1);
lua
colorMul
(number arg1, number arg2)
line 116
// ↓ __mul: Color * scalar or scalar * Color ↓
Lua stack args
1numberarg1
2numberarg2
lua
colorDiv
(number arg2)
line 135
// ↓ __div: Color / scalar ↓
Lua stack args
2numberarg2
lua
colorRound
(nil? arg2)
line 166
// ↓ :round([decimals]) → new Color ↓
Lua stack args
2nil?arg2
lua
colorSet
(number arg2, number arg3, number arg4, nil? arg5)
line 201
// ↓ :set(r, g, b [, a]) — mutates in-place, returns self ↓
Lua stack args
2numberarg2
3numberarg3
4numberarg4
5nil?arg5
lua
colorSetR
(number arg2)
line 215
// ↓ :setR(v) ↓
Lua stack args
2numberarg2
lua
colorSetG
(number arg2)
line 223
// ↓ :setG(v) ↓
Lua stack args
2numberarg2
lua
colorSetB
(number arg2)
line 231
// ↓ :setB(v) ↓
Lua stack args
2numberarg2
lua
colorSetA
(number arg2)
line 239
// ↓ :setA(v) ↓
Lua stack args
2numberarg2
lua
colorLerp
(number arg3)
line 247
// ↓ color:lerp(other, t) linear interpolate between two colors ↓
Lua stack args
3numberarg3
lua
Color
(number? arg1, number? arg2, number? arg3, number? arg4)
line 377
Lua stack args
1number?arg1
2number?arg2
3number?arg3
4number?arg4
cross-refs:vanir.c:? graphics/textures.c:? modules/render.c:? types/common.h:? types/texture.c:?
C Internal
func
pushColor
→ static void
line 7
func
toStringColor
→ static int
line 16
func
colorEq
→ static int
line 80
// ↓ __eq ↓
func
colorAdd
→ static int
line 92
// ↓ __add: component-wise ↓
func
colorSub
→ static int
line 104
// ↓ __sub: component-wise ↓
func
colorToHex
→ static int
line 146
// ↓ :toHex() → string "#RRGGBB" or "#RRGGBBAA" ↓
func
colorClone
→ static int
line 189
// ↓ :clone() ↓
func
colorUnpack
→ static int
line 265
// ↓ :unpack() → r, g, b, a ↓
func
colorToHSV
→ static int
line 275
// ↓ color:toHSV() metafunction, another alias being :rgbToHSV() ↓
func
colorToRGB
→ static int
line 310
// ↓ color:toRGB() metafunction, another alias being :hsvToRGB() ↓
types/common.h
Structs
struct
color
line 19
// ↓ luas color type disassembles to this struct ↓
Plain C mirror of Vanir's Lua Color type. r, g, b, a are normalised floats (0.0–1.0 inside the engine, though the Lua API accepts 0–255 and divides automatically in some paths).
cross-refs:graphics/draw.c:? graphics/rendertarget.c:? graphics/shader.c:? graphics/textures.c:? modules/render.c:? modules/render.h:? modules/windows.c:? modules/windows.h:? types/color.c:?
struct
File
line 24
// ↓ a file handle; stored as lightuserdata inside the lua table ↓
Internal handle wrapping a C FILE* and the original path string. Stored as lightuserdata inside the Lua table returned to scripts.
cross-refs:modules/files.c:? types/file.c:?
Functions
Lua
lua
getfieldf
→ static inline float
line 36
cross-refs:types/angle.c:? types/color.c:? types/matrix.c:? types/quaternion.c:? types/vector.c:?
C Internal
func
pushRegList
→ static inline void
line 30
// ↓ internal helpers ↓
func
addMethods
→ static inline void
line 45
cross-refs:modules/windows.c:? types/angle.c:? types/color.c:? types/matrix.c:? types/quaternion.c:? types/texture.c:? types/vector.c:?
func
degToRad
→ static inline float
line 60
cross-refs:types/angle.c:? types/matrix.c:?
func
radToDeg
→ static inline float
line 64
cross-refs:types/angle.c:? types/matrix.c:?
Macros
#define
COMMON
_H
line 2
#define
M
_PI 3.14159265358979323846
line 13
types/file.c
Functions
C Internal
func
pushFile
→ void
line 23
// ↓ push a new File lua object from an already-open FILE* ↓
↓ add methods and metatable ↓
luaL_newmetatable(L, "vanir.File");
cross-refs:modules/files.c:? types/common.h:?
Externs
extern
fileMethods
const luaL_Reg fileMethods[]
line 24
extern
fileMeta
const luaL_Reg fileMeta[]
line 25
types/matrix.c
Functions
Lua
lua
matGet
→ static void
line 23
// ↓ pull all 9 elements off a table at stack index idx ↓
lua
matMul
(table arg2)
line 139
// ↓ __mul: Matrix * Matrix or Matrix * Vector ↓
Lua stack args
2tablearg2
lua
matGetAngles
→ static int
line 183
// read methods ↓↓↓ read methods | ↓ :getAngles() → Angle (pitch/yaw/roll extracted from rotation columns) ↓
↓ forward column = col 2 ↓
float fx = m[2], fy = m[5], fz = m[8];
↓ right column = col 0 ↓
float fx = m[2], fy = m[5], fz = m[8];
float rx = m[0], ry = m[3], rz = m[6];
lua
matGetScale
→ static int
line 213
// ↓ :getScale() → Vector of column norms ↓
lua
matGetTranslation
→ static int
line 238
// ↓ :getTranslation() → Vector(m[2], m[5], 0) ↓
lua
matGetField
(integer arg2, integer arg3)
line 259
// ↓ :getField(row, col) → number (1-indexed) ↓
Lua stack args
2integerarg2
3integerarg3
lua
matGetForward
→ static int
line 276
// ↓ :getForward() → Vector (column 2) ↓
lua
matGetRight
→ static int
line 297
// ↓ :getRight() → Vector (column 0) ↓
lua
matGetUp
→ static int
line 318
// ↓ :getUp() → Vector (column 1) ↓
lua
matGetRotatedAroundAxis
(number arg3)
line 397
// ↓ :getRotatedAroundAxis(axis_vec, degrees) → new Matrix ↓
Lua stack args
3numberarg3
lua
matGetAxisAngle
→ static int
line 466
// ↓ :getAxisAngle() → axis_vec, angle_degrees ↓
lua
matTranslate
(number arg2, number? arg3)
line 541
// read methods ↑↑↑ read methods | mutating methods ↓↓↓ mutating methods | ↓ :translate(dx, dy [, dz]) — mutates in-place, returns self ↓
Lua stack args
2numberarg2
3number?arg3
lua
matRotate
(number arg2)
line 561
// ↓ :rotate(degrees_or_Angle) — mutates in-place, returns self ↓
Lua stack args
2numberarg2
lua
matScale
(number arg2, number? arg3)
line 593
// ↓ :scale(sx [, sy]) — mutates in-place, returns self ↓
Lua stack args
2numberarg2
3number?arg3
lua
matSetScale
(number arg2, number? arg3, number? arg4)
line 613
// ↓ :setScale(sx, sy [, sz]) — sets column norms, mutates in-place ↓
Lua stack args
2numberarg2
3number?arg3
4number?arg4
↓ normalise each column then rescale ↓
float c0len = sqrtf(m[0]*m[0] + m[3]*m[3] + m[6]*m[6]);
float c1len = sqrtf(m[1]*m[1] + m[4]*m[4] + m[7]*m[7]);
float c2len = sqrtf(m[2]*m[2] + m[5]*m[5] + m[8]*m[8]);
lua
matScaleTranslation
(number arg2)
line 639
// ↓ :scaleTranslation(scalar) — scales translation component only ↓
Lua stack args
2numberarg2
lua
matSetAngles
(number arg2, number? arg3, number? arg4)
line 657
// ↓ :setAngles(p, y, r) or :setAngles(Angle) — sets rotation columns ↓
Lua stack args
2numberarg2
3number?arg3
4number?arg4
↓ right column (col 0) ↓
m[0] = cr*cy + sr*sp*sy;
m[3] = cr*sy - sr*sp*cy;
m[6] = -sr*cp;↓ up column (col 1) ↓
m[1] = -sr*cy + cr*sp*sy;
m[4] = -sr*sy - cr*sp*cy;
m[7] = cr*cp;↓ forward column (col 2) ↓
m[2] = cp*cy;
m[5] = cp*sy;
m[8] = -sp;
lua
matSetTranslation
(number arg2, number? arg3, number? arg4)
line 701
// ↓ :setTranslation(x, y [, z]) or Vector ↓
Lua stack args
2numberarg2
3number?arg3
4number?arg4
lua
matSetField
(integer arg2, integer arg3, number arg4)
line 781
// ↓ :setField(row, col, value) — 1-indexed ↓
Lua stack args
2integerarg2
3integerarg3
4numberarg4
lua
matSetUnpacked
→ static int
line 814
// ↓ :setUnpacked(m1..m9) — set all 9 elements from 9 numbers ↓
lua
matSetAxisAngle
(number arg3)
line 895
// ↓ :setAxisAngle(axis_vec, degrees) — builds rotation matrix ↓
Lua stack args
3numberarg3
lua
matTransformPoint
(number arg2, number arg3)
line 917
// ↓ :transformPoint(x, y) → rx, ry — kept for backwards compat ↓
Lua stack args
2numberarg2
3numberarg3
lua
Matrix
(nil? arg1, nil? arg2)
line 995
// ↓ Matrix(angle_or_nil, vector_or_nil) ↓ | ↓ no args → identity ↓ | ↓ first arg = number → rotation by degrees ↓ | ↓ first arg = Angle → rotation by .y (yaw) ↓ | ↓ second arg = Vector → translation by .x/.y ↓
Lua stack args
1nil?arg1
2nil?arg2
cross-refs:vanir.c:? modules/render.c:? types/common.h:?
C Internal
func
matSet
→ static void
line 34
// ↓ write 9 elements back into the table at stack index idx ↓
func
matPush
→ static void
line 45
// ↓ push a brand-new matrix table with metatable ↓
func
mat3Mul
→ static void
line 57
// ↓ multiply two 3×3 matrices: out = a * b ↓
func
mat3Identity
→ static void
line 70
func
matGetCol
→ static void
line 78
// ↓ column-vector helpers: columns 0/1/2 → right/up/forward ↓
func
matSetCol
→ static void
line 83
func
matToString
→ static int
line 91
// ↓ __tostring ↓
func
matAdd
→ static int
line 109
// ↓ __add: element-wise addition ↓
func
matSub
→ static int
line 124
// ↓ __sub: element-wise subtraction ↓
func
matGetInverse
→ static int
line 339
// ↓ :getInverse() — returns new matrix, general 3×3 inverse ↓
func
matGetInverseTR
→ static int
line 376
// ↓ :getInverseTR() — fast inverse for orthogonal rotation + translation matrix ↓ | ↓ inv(R|t) = R^T | -R^T*t ↓
↓ transpose the 2×2 rotation part ↓
inv[0] = m[0]; inv[1] = m[3]; inv[3] = m[1]; inv[4] = m[4];
inv[6] = 0.0f; inv[7] = 0.0f; inv[8] = 1.0f;↓ -R^T * t ↓
inv[2] = -(inv[0]*m[2] + inv[1]*m[5]);
inv[5] = -(inv[3]*m[2] + inv[4]*m[5]);
func
matIsIdentity
→ static int
line 424
// ↓ :isIdentity() ↓
func
matIsRotationMatrix
→ static int
line 439
// ↓ :isRotationMatrix() — checks columns are orthonormal ↓
↓ check column norms are ~1 and columns are mutually orthogonal ↓
float c0x = m[0], c0y = m[3], c0z = m[6];
float c1x = m[1], c1y = m[4], c1z = m[7];
float c2x = m[2], c2y = m[5], c2z = m[8];
func
matClone
→ static int
line 501
// ↓ :clone() ↓
func
matUnpack
→ static int
line 511
// ↓ :unpack() → 9 numbers ↓
func
matToTable
→ static int
line 523
// ↓ :toTable() → plain table {[1]...[9]} without metatable ↓
func
matSetForward
→ static int
line 724
// ↓ :setForward(vec) — sets column 2 ↓
func
matSetRight
→ static int
line 743
// ↓ :setRight(vec) — sets column 0 ↓
func
matSetUp
→ static int
line 762
// ↓ :setUp(vec) — sets column 1 ↓
func
matSetFrom
→ static int
line 802
// ↓ :set(other) — copies another matrix into self, mutates in-place ↓
func
matSetIdentity
→ static int
line 828
// ↓ :setIdentity() — mutates in-place, returns self ↓
func
matInvert
→ static int
line 840
// ↓ :invert() — mutates in-place using general inverse, returns self ↓
func
matInvertTR
→ static int
line 876
// ↓ :invertTR() — fast transpose inverse for rotation+translation ↓
func
matrixGet
→ void
line 1037
// ↓ public helpers used by render.c ↓
cross-refs:modules/render.c:? types/common.h:?
func
matrixPush
→ void
line 1041
cross-refs:modules/render.c:? types/common.h:?
func
matrixIdentity
→ void
line 1045
cross-refs:modules/render.c:? types/common.h:?
func
matrixTransformPoint
→ void
line 1049
cross-refs:modules/render.c:? types/common.h:?
types/quaternion.c
Functions
Lua
lua
quatSlerp
(number arg3)
line 105
// ↓ quat:slerp(other, t) — spherical linear interpolation ↓
Lua stack args
3numberarg3
↓ flip second quat if dot is negative to take the short arc ↓
if (dot < 0.0f) {
bx=-bx;
by=-by;
bz=-bz;
bw=-bw;
dot=-dot;
}
lua
Quaternion
(number? arg1, number? arg2, number? arg3, number? arg4)
line 192
Lua stack args
1number?arg1
2number?arg2
3number?arg3
4number?arg4
cross-refs:vanir.c:? types/common.h:?
C Internal
func
pushQuat
→ static void
line 8
func
toStringQuat
→ static int
line 17
func
quatMul
→ static int
line 30
// ↓ quat * quat — Hamilton product ↓
func
quatEq
→ static int
line 45
func
quatLength
→ static int
line 58
// ↓ quat:length() — magnitude ↓
func
quatNormalize
→ static int
line 68
// ↓ quat:normalize() ↓
func
quatConjugate
→ static int
line 83
// ↓ quat:conjugate() — same as inverse for unit quaternions ↓
func
quatDot
→ static int
line 93
// ↓ quat:dot(other) ↓
func
quatToAngle
→ static int
line 152
// ↓ quat:toAngle() — converts to Angle (roll/pitch/yaw) in degrees ↓
↓ ZXY order: yaw, roll, pitch ↓
float sinR = 2.0f*(w*x + y*z), cosR = 1.0f - 2.0f*(x*x + y*y);
float sinP = 2.0f*(w*y - z*x);
float sinY = 2.0f*(w*z + x*y), cosY = 1.0f - 2.0f*(y*y + z*z);types/texture.c
Functions
Lua
lua
textureMetaGetColor
(integer arg2, integer arg3)
line 89
// ↓ tex:getColor(x, y) → Color ↓
Lua stack args
2integerarg2
3integerarg3
lua
textureSetImageMeta
(string? path)
line 164
// ↓ tex:setImage(path) — loads a new image into this texture from a file ↓ | ↓ path defaults to tex.path so tex:setImage() reloads the original file ↓
Lua stack args
2string?path
↓ default to the texture's current path so :setImage() acts as a reload ↓
const char *path = luaL_optstring(L, 2, tex->path);
↓ update the baked fields to reflect new image ↓
lua_pushstring(L, tex->path);
lua_setfield(L, 1, "path");
C Internal
func
pushTexture
→ void
line 8
↓ bake plain read-only fields directly onto the table ↓
lua_pushstring(L, tex->name ? tex->name : "");
lua_setfield(L, -2, "name");cross-refs:graphics/rendertarget.c:? graphics/textures.c:? types/common.h:?
func
toStringTexture
→ static int
line 51
func
textureGetWidth
→ static int
line 61
// ↓ tex:getWidth() → width ↓
func
textureGetHeight
→ static int
line 70
// ↓ tex:getHeight() → height ↓
func
textureGetSize
→ static int
line 79
// ↓ tex:getSize() → width, height ↓
func
textureDraw
→ static int
line 134
// ↓ tex:draw(sx, sy, sw, sh, dx, dy [, dw, dh]) ↓ | ↓ temporarily sets this texture as active so drawTexturedRect can find it, then restores the previous one ↓
↓ shift args down: remove self from stack so drawTexturedRect sees sx at 1 ↓
lua_remove(L, 1);
func
textureReleaseMeta
→ static int
line 151
// ↓ tex:release() — frees GPU resources and invalidates this object ↓
types/vector.c
Functions
Lua
lua
vecMul
(number arg1, number arg2)
line 45
// ↓ scalar multiply: vec * number or number * vec ↓
Lua stack args
1numberarg1
2numberarg2
lua
Vector
(number? arg1, number? arg2, number? arg3)
line 162
Lua stack args
1number?arg1
2number?arg2
3number?arg3
cross-refs:vanir.c:? modules/render.c:? types/angle.c:? types/common.h:? types/matrix.c:?
C Internal
func
toStringVec
→ static int
line 7
func
vecAdd
→ static int
line 17
func
vecSub
→ static int
line 30
func
vecUnm
→ static int
line 64
func
vecEq
→ static int
line 76
func
vecLen
→ static int
line 87
// #vec → magnitude
func
vecDot
→ static int
line 94
func
vecCross
→ static int
line 103
func
vecNormalize
→ static int
line 116
func
vecLength
→ static int
line 137