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
line 4
logs.h
Macros
#define
vanir
_log(fmt, ...) \
line 13
#define
vanir
_log_info(fmt, ...) \
line 15
#define
vanir
_log(fmt, ...) ((void)0)
line 18
#define
vanir
_log_info(fmt, ...) ((void)0)
line 19
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/matrix.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 24
// ↓ error handling (clean) ↓
Macros
#define
VANIR
_VERSION
line 4
#define
luaL
_reg luaL_Reg
line 15
#define
throw
(type, name, error) vanir_throw_impl((type), (name), (error)
line 40
// ↓ macro just injects file/line ↓
graphics/draw.c
Functions
Lua
lua
drawLine
(number x1, number y1, number x2, number y2)
line 207
// 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 231
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 259
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 303
// ↓ 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.
if (!hasCb) {
for (int i = 0; i < segs; ++i) {
pushVert(p, x, y, 0, activeColor.r, activeColor.g, activeColor.b, activeColor.a);
pushVert(p, px[i], py[i], 0, activeColor.r, activeColor.g, activeColor.b, activeColor.a);
pushVert(p, px[i+1], py[i+1], 0, activeColor.r, activeColor.g, activeColor.b, activeColor.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 368
// ↓ pre-samples all colors before fan loop so vertex 0's color is only fetched once ↓
Lua stack args
2functionhasCb
↓ pre-sampling happens here ↓
if (!hasCb) {
for (int i = 1; i < n - 1; ++i) {
pushVert(p, vx[0], vy[0], vz[0], activeColor.r, activeColor.g, activeColor.b, activeColor.a);
pushVert(p, vx[i], vy[i], vz[i], activeColor.r, activeColor.g, activeColor.b, activeColor.a);
pushVert(p, vx[i+1], vy[i+1], vz[i+1], activeColor.r, activeColor.g, activeColor.b, activeColor.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);
vc[i] = activeColor;
}cross-refs:graphics/render.h:? modules/render.c:?
lua
drawVertex
(number x, number y, number z)
line 426
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 450
// 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, activeColor.r,activeColor.g,activeColor.b,activeColor.a);
pushVert(p, x+bw, y, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a);
pushVert(p, x+bw, y, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a);
pushVert(p, x+bw, y+bh, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a);
pushVert(p, x+bw, y+bh, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a);
pushVert(p, x, y+bh, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a);
pushVert(p, x, y+bh, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a);
pushVert(p, x, y, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a);
pushCmd(p, DRAW_LINES, 8);
} else {
if (!vertReserve(p, 24))
return 0;top
pushVert(p, x, y, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a); pushVert(p, x+bw, y, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a); pushVert(p, x+bw, y+t, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a);
pushVert(p, x, y, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a); pushVert(p, x+bw, y+t, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a); pushVert(p, x, y+t, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a);bottom
pushVert(p, x, y+bh-t, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a); pushVert(p, x+bw, y+bh-t, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a); pushVert(p, x+bw, y+bh, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a);
pushVert(p, x, y+bh-t, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a); pushVert(p, x+bw, y+bh, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a); pushVert(p, x, y+bh, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a);left
pushVert(p, x, y+t, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a); pushVert(p, x+t, y+t, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a); pushVert(p, x+t, y+bh-t, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a);
pushVert(p, x, y+t, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a); pushVert(p, x+t, y+bh-t, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a); pushVert(p, x, y+bh-t, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a);right
pushVert(p, x+bw-t, y+t, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a); pushVert(p, x+bw, y+t, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a); pushVert(p, x+bw, y+bh-t, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a);
pushVert(p, x+bw-t, y+t, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a); pushVert(p, x+bw, y+bh-t, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.a); pushVert(p, x+bw-t, y+bh-t, 0, activeColor.r,activeColor.g,activeColor.b,activeColor.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 505
// 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 649
// 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 661
// 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 678
// 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 698
// 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 731
// 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 780
// 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 30
// ↓ 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 54
func
pushVert
→ static void
line 81
// ↓ push one vertex into the flat buffer; applies the active matrix transform ↓
cross-refs:modules/render.c:?
func
pushCmd
→ static void
line 97
// ↓ record a draw command for the vertices just pushed; if same type and contiguous then extend ↓
func
flushBatches
→ void
line 120
// ↑ 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 182
// ↓ per vertex color callback helper ↓
func
circlePoints
→ static void
line 189
// ↓ precompute all point positions along circumference, avoids repeat sin/cos ↓
func
pushArc
→ static void
line 532
// ↓ push a filled arc as a triangle fan from (cx,cy); used by rounded box corners ↓
func
drawRoundedBoxInternal
→ static int
line 546
// ↓ internal: draw a rounded rect, per-corner rounding flags ↓
↓ 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 18
Macros
#define
VANIR
_MODULE DRAW
line 11
#define
VERTEX
_STRIDE 7 // x y z r g b a
line 20
#define
VERTEX
_BYTES (VERTEX_STRIDE * sizeof(float))
line 21
#define
M
_PI 3.14159265358979323846
line 24
graphics/render.h
Macros
#define
VANIR
_GRAPHICS
line 2
graphics/rendertarget.c
Functions
Lua
lua
renderTargetCreate
(string name, integer? arg2, integer? arg3)
line 142
// ↓ 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 369
// ↓ 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 417
// ↓ 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 31
// ↓ 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 94
// ↓ (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 214
// ↓ 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 302
// ↓ 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 456
cross-refs:vanir.c:? graphics/rendertarget.h:?
Externs
extern
gpu
struct VanirGPU gpu
line 16
extern
windowPool
struct windowPool windowPool
line 18
Macros
#define
VANIR
_MODULE RENDERTARGET
line 6
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
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 297
// ↓ Lua bindings ↓ | ↓ shader.compile(name, wgsl_source) ↓
Lua stack args
1stringname
2stringsrc
lua
luaShaderSetActive
(string name)
line 308
// ↓ 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 365
// ↓ shader.release(name) ↓
Lua stack args
1stringname
lua
luaShaderExists
(string name)
line 396
Lua stack args
1stringname
lua
luaShaderGetActive
→ static int
line 406
// ↓ 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 416
// ↓ 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 430
// ↓ 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 464
// ↓ 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 487
// ↓ 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 36
// ↓ 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 199
// ↓ flush pending geometry batches before switching pipelines ↓
cross-refs:graphics/shader.h:? modules/windows.h:?
func
drawTexturedQuadImmediate
→ void
line 205
// ↓ 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 277
cross-refs:vanir.c:? graphics/shader.h:?
func
shaderInit
→ int
line 514
cross-refs:vanir.c:? graphics/shader.h:?
Externs
extern
gpu
struct VanirGPU gpu
line 14
extern
windowPool
struct windowPool windowPool
line 15
extern
?
void flushBatches(struct glfwWindow *w)
line 18
// ↓ from graphics/draw.c; declared here to avoid including graphics/render.h which has struct conflicts ↓
Macros
#define
VANIR
_MODULE SHADER
line 6
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
VANIR
_SHADER
line 2
graphics/textures.c
Functions
Lua
lua
pushColorValue
→ static void
line 36
lua
drawTexturedRect
(number? arg1, number? arg2, number? arg3, number? arg4, number? arg5, number? arg6, number? arg7, number? arg8)
line 407
// ↓ 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 449
// ↓ 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 510
// ↓ 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 556
// ↓ textures.getSize(tex) → width, height (module-level convenience) ↓
lua
luaTextureCreateFromImage
→ int
line 590
// ↓ textures.createFromImage(path [, name]) → texture | nil; alias of load ↓
lua
luaTextureGetTexture
→ static int
line 595
// ↓ textures.getTexture(tex) → tex; identity — tex is already a texture object ↓
↓ validates the argument then returns it unchanged ↓
getTexture(L, 1);
lua
luaTextureGetName
→ static int
line 605
// ↓ textures.getName(tex) → string ↓
lua
luaTextureGetShader
→ static int
line 614
// ↓ textures.getShader(tex) → string; always "Textured" in Vanir ↓
lua
luaTextureGetKeyValues
→ static int
line 623
// ↓ textures.getKeyValues(tex) → table ↓
lua
luaTextureGetWidth
→ static int
line 641
// ↓ textures.getWidth(tex) → number ↓
lua
luaTextureGetHeight
→ static int
line 650
// ↓ textures.getHeight(tex) → number ↓
lua
luaTextureGetColor
(integer arg2, integer arg3)
line 659
// ↓ textures.getColor(tex, x, y) → Color ↓
Lua stack args
2integerarg2
3integerarg3
lua
luaTextureGetFloat
(string arg2)
line 678
// ↓ textures.getFloat(tex, key) → number; stub — always 0 ↓
Lua stack args
2stringarg2
lua
luaTextureGetInt
(string arg2)
line 688
// ↓ textures.getInt(tex, key) → number; stub — always 0 ↓
Lua stack args
2stringarg2
lua
luaTextureGetMatrix
(string arg2)
line 698
// ↓ textures.getMatrix(tex, key) → nil; stub ↓
Lua stack args
2stringarg2
lua
luaTextureGetString
(string key)
line 708
// ↓ textures.getString(tex, key) → string | nil ↓
Lua stack args
2stringkey
lua
luaTextureGetVector
(string arg2)
line 724
// ↓ textures.getVector(tex, key) → nil; stub ↓
Lua stack args
2stringarg2
lua
luaTextureGetVectorLinear
→ static int
line 734
// ↓ textures.getVectorLinear(tex, key) → nil; stub ↓
C Internal
func
buildTextureBindGroup
→ static bool
line 60
// ↓ build a sampler + bind group for sampling this texture ↓
func
textureRelease
→ void
line 233
// ↓ 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 264
// ↓ 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 376
// ↓ get a pixel color from cpu-side pixel data ↓
cross-refs:graphics/textures.h:? types/texture.c:?
func
destroyAllTextures
→ void
line 564
cross-refs:vanir.c:? graphics/textures.h:?
func
texturesInit
→ int
line 765
cross-refs:vanir.c:? graphics/textures.h:?
Externs
extern
gpu
struct VanirGPU gpu
line 24
extern
windowPool
struct windowPool windowPool
line 25
Macros
#define
STBI
_NO_THREAD_LOCALS
line 9
// stb_image ↓↓↓ stb_image
#define
STBI
_NO_SIMD
line 10
#define
STB
_IMAGE_IMPLEMENTATION
line 11
#define
VANIR
_MODULE TEXTURES
line 15
// stb_image ↑↑↑ stb_image
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
VANIR
_TEXTURES
line 2
modules/files.c
Functions
Lua
lua
fileClose
(table arg1)
line 25
// ↓ file:close() ↓
Lua stack args
1tablearg1
lua
toStringFile
→ static int
line 49
lua
fileSeek
(integer arg2)
line 85
// ↓ file:seek(n) → None; seeks to absolute byte position ↓
Lua stack args
2integerarg2
lua
fileSkip
(integer arg2)
line 95
// ↓ file:skip(n) → number (resulting position) ↓
Lua stack args
2integerarg2
lua
fileRead
(integer arg2)
line 136
// ↓ file:read(n) → string (raw bytes) ↓
Lua stack args
2integerarg2
lua
fileWrite
(string arg2)
line 183
// ↓ file:write(str) ↓
Lua stack args
2stringarg2
lua
fileWriteByte
(integer arg2)
line 299
// --- typed writes --- | ↓ file:writeByte(x) ↓
Lua stack args
2integerarg2
lua
fileWriteBool
(boolean arg2)
line 309
// ↓ file:writeBool(x) ↓
Lua stack args
2booleanarg2
lua
fileWriteShort
(integer arg2)
line 319
// ↓ file:writeShort(x) ↓
Lua stack args
2integerarg2
lua
fileWriteUShort
(integer arg2)
line 329
// ↓ file:writeUShort(x) ↓
Lua stack args
2integerarg2
lua
fileWriteLong
(integer arg2)
line 339
// ↓ file:writeLong(x) ↓
Lua stack args
2integerarg2
lua
fileWriteULong
(integer arg2)
line 349
// ↓ file:writeULong(x) ↓
Lua stack args
2integerarg2
lua
fileWriteFloat
(number arg2)
line 359
// ↓ file:writeFloat(x) ↓
Lua stack args
2numberarg2
lua
fileWriteDouble
(number arg2)
line 369
// ↓ file:writeDouble(x) ↓
Lua stack args
2numberarg2
lua
fileWriteUInt64
(string arg2)
line 379
// ↓ file:writeUInt64(str) — decimal string ↓
Lua stack args
2stringarg2
lua
filesOpen
(string path, string? mode)
line 439
// ↓ 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
filesRead
(string path)
line 458
// ↓ files.read(path) → string | nil; reads entire file as a string ↓
Lua stack args
1stringpath
lua
filesAsyncRead
(string path, function arg2)
line 499
// ↓ files.asyncRead(path, callback) → nil; reads file asynchronously via a deferred callback ↓ | ↓ in Vanir there is no thread pool yet, so the read happens synchronously on the next call ↓
Lua stack args
1stringpath
2functionarg2
↓ read the file now and call the callback immediately ↓
FILE *f = fopen(path, "rb");
↓ push callback ↓
lua_pushvalue(L, 2);
↓ callback(content, err) ↓
lua_call(L, 2, 0);
lua
filesWrite
(string path, string content)
line 544
// ↓ files.write(path, content) → boolean ↓
Lua stack args
1stringpath
2stringcontent
lua
filesAppend
(string path, string content)
line 566
// ↓ files.append(path, content) → boolean; appends to a file, creating it if needed ↓
Lua stack args
1stringpath
2stringcontent
lua
filesReadTemp
(string name)
line 593
// ↓ files.readTemp(name) → string | nil ↓
Lua stack args
1stringname
lua
filesWriteTemp
(string name, string content)
line 606
// ↓ files.writeTemp(name, content) → boolean ↓
Lua stack args
1stringname
2stringcontent
↓ ensure temp/ directory exists ↓
#ifdef _WIN32
_mkdir("temp");
#else
mkdir("temp", 0755);
#endif
lua
filesExistsTemp
(string name)
line 638
// ↓ files.existsTemp(name) → boolean ↓
Lua stack args
1stringname
lua
filesDeleteTemp
(string name)
line 657
// ↓ files.deleteTemp(name) → boolean ↓
Lua stack args
1stringname
lua
filesExists
(string path)
line 669
// ↓ files.exists(path) → boolean ↓
Lua stack args
1stringpath
lua
filesIsDir
(string path)
line 689
// ↓ files.isDir(path) → boolean ↓
Lua stack args
1stringpath
lua
filesDelete
(string path)
line 704
// ↓ files.delete(path) → boolean ↓
Lua stack args
1stringpath
lua
filesCreateDir
(string path)
line 713
// ↓ files.createDir(path) → boolean ↓
Lua stack args
1stringpath
lua
filesRename
(string from, string to)
line 726
// ↓ files.rename(from, to) → boolean ↓
Lua stack args
1stringfrom
2stringto
lua
filesFind
(string path, string? filter)
line 737
// ↓ files.find(path [, filter]) → table of filenames; non-recursive directory listing ↓ | ↓ filter is a simple suffix string, e.g. ".lua"; nil/empty returns all entries ↓
Lua stack args
1stringpath
2string?filter
lua
filesTime
(string path)
line 812
// ↓ files.time(path) → number; modification time as a Unix timestamp, 0 on error ↓
Lua stack args
1stringpath
C Internal
func
fileFlush
→ static int
line 67
// ↓ file:flush() ↓
func
fileTell
→ static int
line 76
// ↓ file:tell() → number ↓
func
fileSize
→ static int
line 106
// ↓ file:size() → number ↓
cross-refs:graphics/textures.c:? graphics/textures.h:? types/texture.c:?
func
fileEndOfFile
→ static int
line 121
// ↓ file:endOfFile() → boolean ↓
func
fileReadLine
→ static int
line 157
// ↓ file:readLine() → string ↓
↓ strip trailing newline ↓
size_t len = strlen(buf);
func
fileReadByte
→ static int
line 196
// --- typed reads --- | ↓ file:readByte() → number (UInt8) ↓
func
fileReadBool
→ static int
line 207
// ↓ file:readBool() → boolean ↓
func
fileReadShort
→ static int
line 218
// ↓ file:readShort() → number (Int16) ↓
func
fileReadUShort
→ static int
line 229
// ↓ file:readUShort() → number (UInt16) ↓
func
fileReadLong
→ static int
line 240
// ↓ file:readLong() → number (Int32) ↓
func
fileReadULong
→ static int
line 251
// ↓ file:readULong() → number (UInt32) ↓
func
fileReadFloat
→ static int
line 262
// ↓ file:readFloat() → number (Float32) ↓
func
fileReadDouble
→ static int
line 273
// ↓ file:readDouble() → number (Float64) ↓
func
fileReadUInt64
→ static int
line 284
// ↓ file:readUInt64() → string (decimal) ↓
func
filesReadInGame
→ static int
line 493
// ↓ files.readInGame(path) → string | nil; alias of files.read, provided for GMod API parity ↓
func
buildTempPath
→ static void
line 588
// ↓ helper: build a temp path; Vanir temp files live next to the binary ↓
func
filesExistsInGame
→ static int
line 684
// ↓ files.existsInGame(path) → boolean; alias of files.exists ↓
func
filesFindInGame
→ static int
line 807
// ↓ files.findInGame(path [, filter]) → table; alias of files.find ↓
func
filesInit
→ int
line 856
cross-refs:vanir.c:? modules/files.h:?
Macros
#define
mkdir
(p, m) _mkdir(p)
line 12
#define
VANIR
_MODULE FILES
line 18
modules/files.h
Externs
extern
fileMethods
const luaL_Reg fileMethods[]
line 6
extern
fileMeta
const luaL_Reg fileMeta[]
line 7
Macros
#define
VANIR
_FILES
line 2
modules/font.c
Functions
C Internal
func
fontCreate
→ int
line 9
// ↓ font system stub; implement later ↓ | stubs ↓↓↓ stubs ///
func
fontSet
→ int
line 10
func
fontGetSize
→ int
line 11
func
fontMeasure
→ int
line 12
func
fontDrawText
→ int
line 13
func
destroyAllFonts
→ void
line 15
// stubs ↑↑↑ stubs ///
cross-refs:vanir.c:?
func
fontInit
→ int
line 27
cross-refs:vanir.c:? modules/font.h:?
Macros
#define
VANIR
_MODULE FONT
line 1
modules/font.h
Macros
#define
VANIR
_FONT
line 2
modules/hooks.c
Functions
Lua
lua
errorHandler
(string msg)
line 171
// ↓ 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 192
// ↓ 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 245
// ↓ 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 267
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 282
Lua stack args
1stringhookName
C Internal
func
createCallback
→ struct callbacks*
line 17
// ↓ 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 32
// 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 35
cross-refs:modules/hooks.h:?
func
fireError
→ void
line 42
// 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 53
// ↓ 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 66
// ↓ 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 92
// ↓ 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 125
// ↓ 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 155
// ↓ frees all listeners from a hook but keeps it registered ↓
cross-refs:modules/hooks.h:?
func
findHook
→ struct hook*
line 234
// ↓ find a hook in the global pool by name; returns NULL if not found ↓
cross-refs:modules/hooks.h:?
func
hooksRun
→ int
line 296
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 316
cross-refs:vanir.c:? modules/hooks.h:?
Macros
#define
VANIR
_MODULE HOOKS
line 5
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:? modules/render.h:? 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
Macros
#define
VANIR
_HOOKS
line 2
modules/input.c
Functions
Lua
lua
getInputName
(integer arg1)
line 16
// ↓ reverse-lookup: code -> name string, checks keys then mouse buttons, nil if not found ↓
Lua stack args
1integerarg1
lua
lookupBinding
(string name)
line 43
// ↓ input.lookupBinding(name) → code | nil; searches keys then mouse buttons by name ↓
Lua stack args
1stringname
lua
lookupKeyBinding
(string name)
line 76
// ↓ input.lookupKeyBinding(name) → code | nil; searches keys only ↓
Lua stack args
1stringname
lua
isMouseDown
(integer arg1)
line 95
// ↓ input.isMouseDown(button) → boolean; queries the first window for mouse button state ↓
Lua stack args
1integerarg1
lua
setCursorPos
(number arg1, number arg2)
line 165
// ↓ input.setCursorPos(x, y) → nil; sets cursor position on first window ↓
Lua stack args
1numberarg1
2numberarg2
lua
enableCursor
(boolean enable)
line 191
// ↓ input.enableCursor(bool) → nil; show or hide cursor on all windows ↓
Lua stack args
1booleanenable
lua
screenToVector
(number arg1, number arg2)
line 207
// ↓ input.screenToVector(x, y) → Vector; converts screen pixel coords to a normalised 2D vector ↓ | ↓ result is (x/w * 2 - 1, 1 - y/h * 2) matching typical NDC conventions ↓
Lua stack args
1numberarg1
2numberarg2
lua
lockControls
(boolean controlsLocked)
line 260
Lua stack args
1booleancontrolsLocked
lua
getKey
(integer key)
line 305
Lua stack args
1integerkey
cross-refs:modules/input.h:?
lua
isKeyDown
(integer arg1)
line 317
Lua stack args
1integerarg1
lua
getKey
(integer arg1)
line 386
Lua stack args
1integerarg1
cross-refs:modules/input.h:?
C Internal
func
isShiftDown
→ static int
line 112
// ↓ input.isShiftDown() → boolean ↓
func
isControlDown
→ static int
line 129
// ↓ input.isControlDown() → boolean ↓
func
getCursorPos
→ static int
line 146
// ↓ input.getCursorPos() → x, y; returns cursor position in screen coords from first window ↓
func
getCursorVisible
→ static int
line 178
// ↓ input.getCursorVisible() → boolean; true if cursor mode is normal (not hidden/disabled) ↓
func
selectWeapon
→ static int
line 252
// ↓ input.selectWeapon(slot) → nil; stub — no weapon system in Vanir, provided for API completeness ↓
func
isControlLocked
→ static int
line 270
// ↓ input.isControlLocked() → boolean ↓
func
canLockControls
→ static int
line 277
// ↓ input.canLockControls() → boolean; always true in Vanir ↓
func
isGameUIVisible
→ static int
line 284
// ↓ input.isGameUIVisible() → boolean; stub — no game UI layer in Vanir, always false ↓
func
getAnalogValue
→ static int
line 291
// ↓ input.getAnalogValue(code) → number; returns axis value [0, 1] for gamepad axes, 0 for digital keys ↓
func
keyPressHandle
→ void
line 325
func
keyReleaseHandle
→ void
line 342
func
keyPressHandle
→ else
static void
line 383
func
keyReleaseHandle
→ static void
line 385
func
isKeyDown
→ static int
line 400
func
cbKey
→ void
line 435
cross-refs:modules/input.h:? modules/windows.c:?
func
cbMouseButton
→ void
line 457
cross-refs:modules/input.h:? modules/windows.c:?
func
inputInit
→ int
line 479
cross-refs:vanir.c:? modules/input.h:?
Externs
extern
windowPool
struct windowPool windowPool
line 13
Macros
#define
VANIR
_MODULE INPUT
line 5
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
line 2
#define
keyBitmask
0x80
line 8
modules/memory.c
Functions
Lua
lua
parse_u64
→ static int
line 24
// ↓ 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 55
// ↓ 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 190
// ↓ memory.readString(addr, len) → string ↓
Lua stack args
2integerarg2
lua
memReadBytes
(integer arg2)
line 200
// ↓ memory.readBytes(addr, count) → string (raw bytes) ↓
Lua stack args
2integerarg2
lua
memWriteByte
(integer arg2)
line 212
// ↓ write helpers ↓ | ↓ memory.writeByte(addr, value) ↓
Lua stack args
2integerarg2
lua
memWriteShort
(integer arg2)
line 222
// ↓ memory.writeShort(addr, value) ↓
Lua stack args
2integerarg2
lua
memWriteUShort
(integer arg2)
line 231
// ↓ memory.writeUShort(addr, value) ↓
Lua stack args
2integerarg2
lua
memWriteLong
(integer arg2)
line 240
// ↓ memory.writeLong(addr, value) ↓
Lua stack args
2integerarg2
lua
memWriteULong
(integer arg2)
line 249
// ↓ memory.writeULong(addr, value) ↓
Lua stack args
2integerarg2
lua
memWriteFloat
(number arg2)
line 258
// ↓ memory.writeFloat(addr, value) ↓
Lua stack args
2numberarg2
lua
memWriteDouble
(number arg2)
line 267
// ↓ memory.writeDouble(addr, value) ↓
Lua stack args
2numberarg2
lua
memWriteBool
(boolean arg2)
line 298
// ↓ memory.writeBool(addr, value) ↓
Lua stack args
2booleanarg2
lua
memWriteString
(string arg2)
line 307
// ↓ memory.writeString(addr, str) — writes raw bytes, no null terminator ↓
Lua stack args
2stringarg2
lua
memGetAddr
(string arg1)
line 323
// ↓ 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 334
// ↓ memory.toHex(addr) → string — format address as hex string ↓
Lua stack args
1integerarg1
lua
memProtect
(integer arg2, integer arg3)
line 346
// ↓ memory.protect(addr, size, prot) — change memory protection flags (windows) ↓
Lua stack args
2integerarg2
3integerarg3
C Internal
func
memReadByte
→ static int
line 89
// ↓ read helpers — each returns 1 value or errors ↓ | ↓ memory.readByte(addr) → number ↓
func
memReadShort
→ static int
line 98
// ↓ memory.readShort(addr) → number (Int16) ↓
func
memReadUShort
→ static int
line 108
// ↓ memory.readUShort(addr) → number (UInt16) ↓
func
memReadLong
→ static int
line 118
// ↓ memory.readLong(addr) → number (Int32) ↓
func
memReadULong
→ static int
line 128
// ↓ memory.readULong(addr) → number (UInt32) ↓
func
memReadFloat
→ static int
line 138
// ↓ memory.readFloat(addr) → number (Float32) ↓
func
memReadDouble
→ static int
line 148
// ↓ memory.readDouble(addr) → number (Float64) ↓
func
memReadInt64
→ static int
line 158
// ↓ memory.readInt64(addr) → string (because lua integers may be 32-bit on some builds) ↓
func
memReadUInt64
→ static int
line 168
// ↓ memory.readUInt64(addr) → string (decimal) to avoid sign loss ↓
func
memReadBool
→ static int
line 180
// ↓ memory.readBool(addr) → boolean ↓
func
memWriteInt64
→ static int
line 276
// ↓ memory.writeInt64(addr, value|string) ↓
func
memWriteUInt64
→ static int
line 287
// ↓ memory.writeUInt64(addr, value|string) ↓
func
memWriteBytes
→ static int
line 317
// ↓ memory.writeBytes(addr, str) — alias for writeString ↓
func
memPageConstants
→ static int
line 359
// ↓ windows memory page protection constants ↓
func
memoryInit
→ int
line 414
cross-refs:vanir.c:? modules/memory.h:?
Macros
#define
VANIR
_MODULE MEMORY
line 7
modules/memory.h
Macros
#define
VANIR
_MEMORY
line 2
modules/render.c
Functions
Lua
lua
selectRender
(userdata arg1)
line 83
// 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.
↓ window was already destroyed and freed; Lua userdata pointer was nulled ↓
if (!w)
return 0;↓ 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 185
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
↓ window was already destroyed and freed; Lua userdata pointer was nulled ↓
if (!w)
return 0;↓ 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 244
// ↓ 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
↓ window was already destroyed and freed; Lua userdata pointer was nulled ↓
if (!w) return 0;
↓ 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 314
// ↓ releases pipeline resources for a window ↓
Lua stack args
1userdataarg1
cross-refs:vanir.c:? graphics/rendertarget.h:? graphics/shader.h:? graphics/textures.h:? types/texture.c:?
lua
colorFromTable
→ static void
line 340
// ↓ read color from a lua table at stack index idx (r,g,b,a fields, 0-255) ↓
lua
setTexture
(nil arg1)
line 363
Lua stack args
1nilarg1
cross-refs:graphics/rendertarget.h:? graphics/textures.c:? modules/render.h:? types/texture.c:?
lua
setBlend
(integer source, integer blend)
line 378
// ↑ 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 387
Lua stack args
1integercap
TODO(webgpu): map cap to the appropriate pipeline field.
cross-refs:modules/input.c:? modules/render.h:? modules/windows.c:?
lua
disable
(integer cap)
line 395
Lua stack args
1integercap
cross-refs:modules/render.h:? modules/windows.c:?
lua
clear
(nil? arg1)
line 405
// ↓ 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 432
// 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 489
// render.renderTargetExists(string name) → boolean
Lua stack args
1stringname
cross-refs:modules/render.h:?
lua
destroyRenderTarget
(string name)
line 505
// 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 539
Lua stack args
1integerarg1
lua
pushMatrix
(nil? arg1)
line 558
// 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(matStack.saved[matStack.top], matStack.active, sizeof(matStack.active));
matStack.top++;↓ if a Matrix table was passed, load it as the new active matrix ↓
if (!lua_isnoneornil(L, 1)) {
matrixGet(L, 1, matStack.active);
matrixCheckIdentity();cross-refs:modules/render.h:?
lua
setMatrix
(table arg1)
line 614
// render.setMatrix(mat) ↓
Lua stack args
1tablearg1
cross-refs:types/quaternion.c:? types/texture.c:?
lua
scissor
(number arg1, number arg2, number arg3, number arg4)
line 644
Lua stack args
1numberarg1
2numberarg2
3numberarg3
4numberarg4
lua
setViewport
(number arg1, number arg2, number arg3, number arg4)
line 664
// ↓ 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 30
// ↓ 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 ↑
cross-refs:graphics/shader.h:?
func
endPass
→ static void
line 73
// ↓ stopRender closes the pass, then flushBatches opens another to upload and draw cpu batch ↓
func
setColor
→ int
line 357
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 428
// 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 457
// 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 461
// render.enableDepth(boolean enable) | No depth buffer in this 2D pipeline — no-op stub
cross-refs:modules/render.h:?
func
pushCustomClipPlane
→ int
line 465
// render.pushCustomClipPlane(Vector normal, number distance) | WebGPU has no clip plane API — no-op stub
cross-refs:modules/render.h:?
func
popCustomClipPlane
→ int
line 468
// render.popCustomClipPlane()
cross-refs:modules/render.h:?
func
renderViewsLeft
→ int
line 472
// render.renderViewsLeft() → number | This engine renders one view per frame; returns 1 for compatibility
cross-refs:modules/render.h:?
func
readPixel
→ int
line 479
// 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 538
// stubs ↓↓↓ stubs
func
end
→ int
line 540
cross-refs:modules/files.c:? modules/memory.c:?
func
matrixCheckIdentity
→ static void
line 545
func
popMatrix
→ int
line 584
// render.popMatrix() ↓
func
resetMatrix
→ int
line 602
// render.resetMatrix() ↓
func
getMatrix
→ static int
line 627
// render.getMatrix() → Matrix ↓
cross-refs:graphics/textures.c:? types/quaternion.c:? types/texture.c:?
func
applyActiveMatrix
→ void
line 633
// ↓ 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 692
// ↓ reset viewport to the full framebuffer ↓
cross-refs:modules/render.h:?
func
setQuality
→ int
line 711
cross-refs:modules/render.h:?
func
renderInit
→ int
line 782
zero-init sets top=0
matrixIdentity(matStack.active);
luaL_newlib(L, luaRender);cross-refs:vanir.c:? modules/render.h:?
Externs
extern
gpu
struct VanirGPU gpu
line 18
extern
activeShader
struct Shader *activeShader
line 21
// ↓ activeShader is owned by graphics/shader.c; NULL means use the built-in pipeline ↓
Macros
#define
VANIR
_MODULE RENDER
line 7
modules/render.h
Structs
struct
matrixStack
line 47
// ↓ matrices saved by pushMatrix ↓// ↓ number of saved matrices ↓// ↓ current transform applied to all verts ↓// ↓ fast path: skip transform when identity ↓
cross-refs:modules/render.c:?
Externs
extern
activeColor
struct color activeColor
line 37
// ↓ active color; written by render.setColor, read directly by draw calls ↓
extern
activeTexture
struct Texture *activeTexture
line 40
// ↓ active texture; written by render.setTexture, read by textured draw calls ↓
extern
currentRenderWindow
struct glfwWindow *currentRenderWindow
line 42
extern
matStack
struct matrixStack matStack
line 54
Macros
#define
VANIR
_RENDER
line 2
#define
MATRIX
_STACK_MAX 64
line 45
// ↓ matrix stack: active transform applied to all verts, with save/restore depth ↓
modules/system.c
Functions
Lua
lua
getScreenSize
(integer? arg1)
line 144
// ↓ 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 170
Lua stack args
1stringtext
cross-refs:modules/system.h:?
lua
getEnv
(string key)
line 187
// ↓ environment variable ↓
Lua stack args
1stringkey
cross-refs:modules/system.h:?
lua
systemSleep
(integer ms)
line 262
// ↓ 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 282
// ↓ 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 24
// ↓ current logged-in username ↓
cross-refs:modules/system.h:?
func
getOS
→ int
line 51
// ↓ OS name string ↓
cross-refs:modules/system.h:?
func
getSystemInfo
→ int
line 66
// ↓ kernel/system info table: { sysname, nodename, release, version, machine } ↓
cross-refs:modules/system.h:?
func
getMonitorCount
→ int
line 112
// ↓ monitor count ↓
cross-refs:modules/system.h:?
func
getMonitors
→ int
line 122
// ↓ monitor info table array; { width, height, refreshRate, name } per entry ↓
cross-refs:modules/system.h:?
func
getClipboard
→ int
line 160
// ↓ clipboard read / write ↓
cross-refs:modules/system.h:?
func
getTime
→ int
line 180
// ↓ wall clock time in seconds (double) ↓
cross-refs:modules/system.h:?
func
getCPUCount
→ int
line 200
// ↓ 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 216
// ↓ 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 237
// ↓ 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 291
// ↓ 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 343
cross-refs:vanir.c:? modules/system.h:?
Macros
#define
VANIR
_MODULE SYSTEM
line 6
modules/system.h
Macros
#define
VANIR
_SYSTEM
line 2
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 18
// ↓ 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 125
// ↓ 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 205
// ↓ 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 241
// ↓ 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 259
// ↓ timer.remove(name) → None ↓
Lua stack args
1stringname
lua
timerExists
(string name)
line 273
// ↓ timer.exists(name) → boolean ↓
Lua stack args
1stringname
lua
timerStart
(string name)
line 282
// ↓ timer.start(name) → boolean — restart a stopped/finished timer from now ↓
Lua stack args
1stringname
lua
timerStop
(string name)
line 302
// ↓ timer.stop(name) → boolean — stops (deactivates) a timer without removing it ↓
Lua stack args
1stringname
lua
timerPause
(string name)
line 320
// ↓ timer.pause(name) → boolean ↓
Lua stack args
1stringname
lua
timerUnpause
(string name)
line 339
// ↓ 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 362
// ↓ 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 386
// ↓ timer.adjust(name, delay, reps|nil, func|nil) → boolean ↓
Lua stack args
1stringname
2numberdelay
3integerarg3
4nilarg4
lua
timerTimeleft
(string name)
line 414
// ↓ 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 439
// ↓ timer.repsleft(name) → number | nil ↓
Lua stack args
1stringname
C Internal
func
rawMilliseconds
→ static int64_t
line 44
func
nowMs
→ static double
line 61
func
nowSec
→ static double
line 67
// ↓ 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 174
// ↓ realtime() → number — monotonic ms since process start ↓
func
systime
→ int
line 181
// ↓ systime() → number — unix epoch seconds as float ↓
func
curtime
→ int
line 188
// ↓ curtime() → number — seconds since vanirInit ↓
func
frametime
→ int
line 198
// ↓ frametime() → number — ms of the last frame ↓
func
timerGetTimersLeft
→ int
line 451
// ↓ timer.getTimersLeft() → number — count of active, unfinished timers ↓
func
timerInit
→ int
line 485
cross-refs:vanir.c:? modules/timer.h:?
Macros
#define
VANIR
_MODULE TIMER
line 6
modules/timer.h
Macros
#define
VANIR
_TIMER
line 2
modules/windows.c
Functions
Lua
lua
isHovering
(userdata arg1)
line 321
// window metafunctions ↓↓↓ window metafunctions
Lua stack args
1userdataarg1
lua
isFocused
(userdata arg1)
line 334
Lua stack args
1userdataarg1
lua
getTitle
(userdata arg1)
line 348
Lua stack args
1userdataarg1
lua
getID
(userdata arg1)
line 356
Lua stack args
1userdataarg1
lua
getMouse
(userdata arg1)
line 366
// ↓ returns nil, nil if mouse is off window ↓
Lua stack args
1userdataarg1
lua
getSize
(userdata arg1)
line 387
// ↓ 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 402
Lua stack args
1userdataarg1
lua
setTitle
(userdata arg1, string title)
line 425
// ↓ set window title at runtime ↓
Lua stack args
1userdataarg1
2stringtitle
lua
setPos
(userdata arg1, integer x, integer y)
line 436
// ↓ move window to screen position ↓
Lua stack args
1userdataarg1
2integerx
3integery
lua
getPos
(userdata arg1)
line 450
// ↓ get window screen position ↓
Lua stack args
1userdataarg1
lua
setSize
(userdata arg1, integer width, integer height)
line 462
// ↓ resize window ↓
Lua stack args
1userdataarg1
2integerwidth
3integerheight
lua
setIcon
(userdata arg1, integer width, integer height, string pixels)
line 473
// ↓ 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 502
// ↓ set window opacity (0.0 - 1.0) ↓
Lua stack args
1userdataarg1
2numberarg2
lua
setAlwaysOnTop
(userdata arg1, boolean ontop)
line 512
// ↓ toggle always-on-top / floating hint ↓
Lua stack args
1userdataarg1
2booleanontop
lua
setFullscreen
(userdata arg1, boolean enabled, integer? arg3)
line 522
// ↓ 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 549
// ↓ focus (raise) the window ↓
Lua stack args
1userdataarg1
lua
minimize
(userdata arg1, boolean iconify)
line 558
// ↓ minimize/iconify or restore ↓
Lua stack args
1userdataarg1
2booleaniconify
lua
setDecorated
(userdata arg1, boolean decorated)
line 568
// ↓ show / hide window decorations (title bar, border) ↓
Lua stack args
1userdataarg1
2booleandecorated
lua
setResizable
(userdata arg1, boolean resizable)
line 578
// ↓ enable / disable user resize ↓
Lua stack args
1userdataarg1
2booleanresizable
lua
setAspectRatio
(userdata arg1, integer numer, integer denom)
line 588
// ↓ 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 606
// ↓ 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 619
// ↓ set cursor mode: CURSOR_NORMAL / CURSOR_HIDDEN / CURSOR_DISABLED ↓
Lua stack args
1userdataarg1
2integermode
lua
setCursorShape
(userdata arg1, integer shape)
line 629
// ↓ set cursor to a standard shape (CURSOR_SHAPE enum) ↓
Lua stack args
1userdataarg1
2integershape
lua
resetCursor
(userdata arg1)
line 647
// ↓ reset to default arrow cursor ↓
Lua stack args
1userdataarg1
lua
requestAttention
(userdata arg1)
line 656
// ↓ flash the window taskbar entry to grab attention ↓
Lua stack args
1userdataarg1
lua
restore
(userdata arg1)
line 665
// ↓ restore an iconified or maximized window back to normal ↓
Lua stack args
1userdataarg1
cross-refs:graphics/rendertarget.c:? graphics/shader.c:? modules/render.c:? modules/render.h:?
lua
maximize
(userdata arg1)
line 674
// ↓ maximize window to fill monitor work area ↓
Lua stack args
1userdataarg1
lua
setVisible
(userdata arg1, boolean visible)
line 683
// ↓ show / hide a window without destroying it ↓
Lua stack args
1userdataarg1
2booleanvisible
lua
setRawMouse
(userdata arg1, boolean enabled)
line 694
// ↓ 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 1223
// ↓ 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;↓ back-pointer so we can null it on free ↓
struct glfwWindow **udata = (struct glfwWindow **)lua_newuserdata(L, sizeof(struct glfwWindow *));
*udata = window;
window->udata = udata;↓ 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 37
// ↓ webgpu async callbacks ↓
TODO: maybe change this later
if (status == WGPURequestAdapterStatus_Success) *(WGPUAdapter *)ud1 = a;
func
on_device
→ static void
line 40
func
vanirGPUInit
→ bool
line 47
// ↑ webgpu async callbacks ↑ | ↓ shared gpu init not used; however, here for explicit init if needed ↓
cross-refs:modules/windows.h:?
func
vanirGPUDestroy
→ void
line 100
// ↓ 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 137
func
cbCursorEnter
→ static void
line 174
func
cbFocus
→ static void
line 186
func
cbClose
→ static void
line 200
// ↓ marks for deferred free; cleanup happens next frame ↓
func
releaseFrame
→ void
line 216
// glfw callbacks ↑↑↑ glfw callbacks | ↓ frame release ↓
cross-refs:vanir.c:? modules/render.c:? modules/windows.h:?
func
destroyPipeline
→ void
line 247
// ↑ frame release ↑ | ↓ pipeline lifecycle ↓
// ↑ kind of unholy ↑
cross-refs:vanir.c:? modules/render.c:? modules/windows.h:?
func
destroyWindowResources
→ static void
line 263
↓ tear down the shared GPU context when the last window is gone ↓
if (windowPool.count == 1)
vanirGPUDestroy();
func
renderHandle
→ void
line 286
// ↑ pipeline lifecycle ↑ | ↓ render hook handle ↓
↓ deferred window freeing ↓
for (size_t i = 0; i < windowPool.count; ) {
struct glfwWindow *w = windowPool.windows[i];↓ null out the Lua userdata pointer before freeing so any subsequent ↓
if (w->quit) {
if (w->udata) {
*w->udata = NULL;
w->udata = NULL;
}↓ 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 732
// ↑ 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 839
// ↓ 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 1031
// 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 1279
cross-refs:vanir.c:? modules/windows.h:?
Macros
#define
VANIR
_MODULE WINDOWS
line 8
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:? types/texture.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() ↓// ↓ pointer to the Lua userdata slot; nulled before free to prevent use-after-free ↓// ↓ 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 97
cross-refs:vanir.c:? graphics/rendertarget.c:? graphics/shader.c:? graphics/textures.c:? modules/input.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 119
extern
preDrawOpaque
struct hook preDrawOpaque
line 121
extern
postDrawOpaque
struct hook postDrawOpaque
line 122
extern
preDrawTranslucent
struct hook preDrawTranslucent
line 123
extern
postDrawTranslucent
struct hook postDrawTranslucent
line 124
Macros
#define
VANIR
_WINDOWS
line 2
#define
TEXTURED
_VERTEX_STRIDE 6 // ↓ xyzw + uv ↓
line 114
// ↓ textured draw helpers; implemented in graphics/shader.c ↓
types/angle.c
Functions
Lua
lua
angleMul
(number arg1, number arg2)
line 32
// ↓ __mul: Angle * scalar or scalar * Angle ↓
Lua stack args
1numberarg1
2numberarg2
lua
angleDiv
(number arg2)
line 51
// ↓ __div: Angle / scalar ↓
Lua stack args
2numberarg2
lua
angleRotateAroundAxis
(number arg3)
line 167
// ↓ :rotateAroundAxis(axis_vec, degrees) → new Angle ↓
Lua stack args
3numberarg3
lua
angleSet
(number arg2, number arg3, number arg4)
line 220
// ↓ :set(p, y, r) — mutates in-place, returns self ↓
Lua stack args
2numberarg2
3numberarg3
4numberarg4
lua
angleIndex
(string key)
line 252
// ↓ __index — expose p/y/r fields from userdata to Lua ↓ | ↓ also exposes pitch/yaw/roll aliases (used by Quaternion:toAngle etc.) ↓
Lua stack args
2stringkey
↓ long-name aliases ↓
if (strcmp(key, "pitch") == 0) { lua_pushnumber(L, a->p); return 1; }
if (strcmp(key, "yaw") == 0) { lua_pushnumber(L, a->y); return 1; }
if (strcmp(key, "roll") == 0) { lua_pushnumber(L, a->r); return 1; }↓ fall through to method table ↓
indexFallback(L, "vanir.Angle", key);
lua
angleNewIndex
(string key, number arg3)
line 274
// ↓ __newindex — allow a.p = n and a.pitch = n style assignment ↓
Lua stack args
2stringkey
3numberarg3
↓ long-name aliases ↓
if (strcmp(key, "pitch") == 0) { a->p = val; return 0; }
if (strcmp(key, "yaw") == 0) { a->y = val; return 0; }
if (strcmp(key, "roll") == 0) { a->r = val; return 0; }
lua
Angle
(number? arg1, number? arg2, number? arg3)
line 325
// ↓ 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:? types/vector.c:?
C Internal
func
toStringAngle
→ static int
line 23
// ↓ __tostring ↓
func
angleUnm
→ static int
line 61
// ↓ __unm: -Angle ↓
func
angleEq
→ static int
line 70
// ↓ __eq ↓
func
angleAdd
→ static int
line 80
// ↓ __add ↓
func
angleSub
→ static int
line 90
// ↓ __sub ↓
func
angleIsZero
→ static int
line 100
// ↓ :isZero() ↓
func
angleGetForward
→ static int
line 109
// ↓ :getForward() → Vector ↓
func
angleGetRight
→ static int
line 127
// ↓ :getRight() → Vector ↓
func
angleGetUp
→ static int
line 147
// ↓ :getUp() → Vector ↓
func
angleRound
→ static int
line 197
// ↓ :round([decimals]) → new Angle ↓
func
angleClone
→ static int
line 211
// ↓ :clone() ↓
func
angleSetZero
→ static int
line 233
// ↓ :setZero() — mutates in-place, returns self ↓
func
angleSetP
→ static int
line 246
// ↓ :setP/Y/R(v) ↓
func
angleSetY
→ static int
line 247
func
angleSetR
→ static int
line 248
Macros
#define
VANIR
_MODULE ANGLE
line 1
types/color.c
Functions
Lua
lua
colorConcat
→ static int
line 32
// ↓ __concat: Color .. Color or Color .. string ↓
// ↑ convert both operands to string, concatenate ↑
lua
colorMul
(number arg1, number arg2)
line 85
// ↓ __mul: Color * scalar or scalar * Color ↓
Lua stack args
1numberarg1
2numberarg2
lua
colorDiv
(number arg2)
line 104
// ↓ __div: Color / scalar ↓
Lua stack args
2numberarg2
lua
colorSet
(number arg2, number arg3, number arg4, nil? arg5)
line 155
// ↓ :set(r, g, b [, a]) — mutates in-place, returns self ↓
Lua stack args
2numberarg2
3numberarg3
4numberarg4
5nil?arg5
lua
colorLerp
(number arg3)
line 177
// ↓ color:lerp(other, t) linear interpolate between two colors ↓
Lua stack args
3numberarg3
lua
colorIndex
(string key)
line 279
// ↓ __index — expose r/g/b/a fields from userdata to Lua ↓
Lua stack args
2stringkey
↓ fall through to method table ↓
indexFallback(L, "vanir.Color", key);
lua
colorNewIndex
(string key, number arg3)
line 297
// ↓ __newindex — allow c.r = n style assignment ↓
Lua stack args
2stringkey
3numberarg3
lua
Color
(number? arg1, number? arg2, number? arg3, number? arg4)
line 344
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
toStringColor
→ static int
line 22
func
colorEq
→ static int
line 55
// ↓ __eq ↓
func
colorAdd
→ static int
line 65
// ↓ __add: component-wise ↓
func
colorSub
→ static int
line 75
// ↓ __sub: component-wise ↓
func
colorToHex
→ static int
line 114
// ↓ :toHex() → string "#RRGGBB" or "#RRGGBBAA" ↓
func
colorRound
→ static int
line 131
// ↓ :round([decimals]) → new Color ↓
func
colorClone
→ static int
line 146
// ↓ :clone() ↓
func
colorSetR
→ static int
line 171
// ↓ :setR/G/B/A(v) ↓
func
colorSetG
→ static int
line 172
func
colorSetB
→ static int
line 173
func
colorSetA
→ static int
line 174
func
colorUnpack
→ static int
line 193
// ↓ :unpack() → r, g, b, a ↓
func
colorToHSV
→ static int
line 205
// ↓ color:toHSV() metafunction, another alias being :rgbToHSV() ↓
func
colorToRGB
→ static int
line 241
// ↓ color:toRGB() metafunction, another alias being :hsvToRGB() ↓
Macros
#define
VANIR
_MODULE COLOR
line 1
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:?
struct
VanirVec
line 30
// ↓ userdata structs for value types — one allocation per object, no table overhead ↓
cross-refs:types/angle.c:? types/matrix.c:? types/quaternion.c:? types/vector.c:?
struct
VanirAng
line 31
cross-refs:types/angle.c:? types/quaternion.c:? types/vector.c:?
struct
VanirQuat
line 32
cross-refs:types/quaternion.c:?
struct
VanirCol
line 33
cross-refs:types/color.c:?
Functions
Lua
lua
getField
→ static inline float
line 48
cross-refs:types/matrix.c:? types/vector.c:?
lua
roundMultiplier
→ static inline float
line 101
// ↓ roundMultiplier: computes 10^dec for :round([decimals]) helpers ↓
cross-refs:types/angle.c:? types/color.c:? types/quaternion.c:? types/vector.c:?
lua
indexFallback
→ static inline void
line 175
// ↓ indexFallback: look up key in the __methods sub-table of a named metatable ↓ | ↓ leaves one value on the stack (the method or nil) ↓
↓ pop __methods, keep result ↓
if (!lua_isnil(L, -1)) {
lua_getfield(L, -1, key);
lua_remove(L, -2);↓ pop metatable ↓
lua_remove(L, -2);
} else {↓ pop nil __methods + metatable ↓
} else {
lua_pop(L, 2);
lua_pushnil(L);
}cross-refs:types/angle.c:? types/color.c:? types/quaternion.c:? types/vector.c:?
C Internal
func
pushRegList
→ static inline void
line 42
// ↓ internal helpers ↓
func
addMethods
→ static inline void
line 59
// ↓ addMethods: original table-based __index helper, used by window and Matrix ↓
cross-refs:modules/windows.c:? types/matrix.c:? types/texture.c:?
func
addMethodsUD
→ static inline void
line 76
// ↓ addMethodsUD: userdata variant — stores methods in __methods for custom __index handlers ↓ | ↓ used by Vector, Angle, Quaternion, Color whose __index handles field access first ↓
↓ first registration: populate the metatable ↓
if (luaL_newmetatable(L, name)) {
if (methods) {
lua_newtable(L);
pushRegList(L, methods);
lua_setfield(L, -2, "__methods");
}cross-refs:types/angle.c:? types/color.c:? types/quaternion.c:? types/vector.c:?
func
degToRad
→ static inline float
line 91
cross-refs:types/angle.c:? types/matrix.c:? types/quaternion.c:? types/vector.c:?
func
radToDeg
→ static inline float
line 95
cross-refs:types/angle.c:? types/matrix.c:? types/vector.c:?
func
angToQuat
→ static inline void
line 116
// ↓ angToQuat: build quaternion components from a VanirAng (ZYX: yaw, pitch, roll) ↓ | ↓ used by vecRotate / vecGetRotated to avoid duplicating the full derivation ↓
cross-refs:types/vector.c:?
Macros
#define
VANIR
_COMMON
line 2
#define
M
_PI 3.14159265358979323846
line 13
#define
setField
(check, field) \
line 132
// ↓ setField: expand a single-field setter that mutates in-place and returns self ↓
types/file.c
Functions
C Internal
func
pushFile
→ void
line 25
// ↓ 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 26
extern
fileMeta
const luaL_Reg fileMeta[]
line 27
Macros
#define
VANIR
_MODULE FILE
line 1
types/matrix.c
Functions
Lua
lua
matGet
→ static void
line 25
// ↓ pull all 9 elements off a table at stack index idx ↓
lua
matGetAngles
→ static int
line 174
// 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 204
// ↓ :getScale() → Vector of column norms ↓
lua
matGetTranslation
→ static int
line 229
// ↓ :getTranslation() → Vector(m[2], m[5], 0) ↓
lua
matGetField
(integer arg2, integer arg3)
line 250
// ↓ :getField(row, col) → number (1-indexed) ↓
Lua stack args
2integerarg2
3integerarg3
lua
matGetForward
→ static int
line 267
// ↓ :getForward() → Vector (column 2) ↓
lua
matGetRight
→ static int
line 288
// ↓ :getRight() → Vector (column 0) ↓
lua
matGetUp
→ static int
line 309
// ↓ :getUp() → Vector (column 1) ↓
lua
matGetRotatedAroundAxis
(number arg3)
line 388
// ↓ :getRotatedAroundAxis(axis_vec, degrees) → new Matrix ↓
Lua stack args
3numberarg3
lua
matGetAxisAngle
→ static int
line 457
// ↓ :getAxisAngle() → axis_vec, angle_degrees ↓
lua
matTranslate
(number arg2, number? arg3)
line 532
// 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 552
// ↓ :rotate(degrees_or_Angle) — mutates in-place, returns self ↓
Lua stack args
2numberarg2
lua
matScale
(number arg2, number? arg3)
line 584
// ↓ :scale(sx [, sy]) — mutates in-place, returns self ↓
Lua stack args
2numberarg2
3number?arg3
lua
matSetScale
(number arg2, number? arg3, number? arg4)
line 604
// ↓ :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 630
// ↓ :scaleTranslation(scalar) — scales translation component only ↓
Lua stack args
2numberarg2
lua
matSetAngles
(number arg2, number? arg3, number? arg4)
line 648
// ↓ :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 692
// ↓ :setTranslation(x, y [, z]) or Vector ↓
Lua stack args
2numberarg2
3number?arg3
4number?arg4
lua
matSetField
(integer arg2, integer arg3, number arg4)
line 772
// ↓ :setField(row, col, value) — 1-indexed ↓
Lua stack args
2integerarg2
3integerarg3
4numberarg4
lua
matSetUnpacked
→ static int
line 805
// ↓ :setUnpacked(m1..m9) — set all 9 elements from 9 numbers ↓
lua
matSetAxisAngle
(number arg3)
line 886
// ↓ :setAxisAngle(axis_vec, degrees) — builds rotation matrix ↓
Lua stack args
3numberarg3
lua
matTransformPoint
(number arg2, number arg3)
line 908
// ↓ :transformPoint(x, y) → rx, ry — kept for backwards compat ↓
Lua stack args
2numberarg2
3numberarg3
lua
Matrix
(nil? arg1, nil? arg2)
line 986
// ↓ 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:? types/quaternion.c:?
C Internal
func
matSet
→ static void
line 36
// ↓ write 9 elements back into the table at stack index idx ↓
func
matPush
→ static void
line 47
// ↓ push a brand-new matrix table with metatable ↓
func
mat3Mul
→ static void
line 59
// ↓ multiply two 3×3 matrices: out = a * b ↓
func
mat3Identity
→ static void
line 72
func
matGetCol
→ static void
line 80
// ↓ column-vector helpers: columns 0/1/2 → right/up/forward ↓
func
matSetCol
→ static void
line 85
func
matToString
→ static int
line 93
// ↓ __tostring ↓
func
matAdd
→ static int
line 111
// ↓ __add: element-wise addition ↓
func
matSub
→ static int
line 126
// ↓ __sub: element-wise subtraction ↓
func
matMul
→ static int
line 141
// ↓ __mul: Matrix * Matrix or Matrix * Vector ↓
func
matGetInverse
→ static int
line 330
// ↓ :getInverse() — returns new matrix, general 3×3 inverse ↓
func
matGetInverseTR
→ static int
line 367
// ↓ :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 415
// ↓ :isIdentity() ↓
func
matIsRotationMatrix
→ static int
line 430
// ↓ :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 492
// ↓ :clone() ↓
func
matUnpack
→ static int
line 502
// ↓ :unpack() → 9 numbers ↓
func
matToTable
→ static int
line 514
// ↓ :toTable() → plain table {[1]...[9]} without metatable ↓
func
matSetForward
→ static int
line 715
// ↓ :setForward(vec) — sets column 2 ↓
func
matSetRight
→ static int
line 734
// ↓ :setRight(vec) — sets column 0 ↓
func
matSetUp
→ static int
line 753
// ↓ :setUp(vec) — sets column 1 ↓
func
matSetFrom
→ static int
line 793
// ↓ :set(other) — copies another matrix into self, mutates in-place ↓
func
matSetIdentity
→ static int
line 819
// ↓ :setIdentity() — mutates in-place, returns self ↓
func
matInvert
→ static int
line 831
// ↓ :invert() — mutates in-place using general inverse, returns self ↓
func
matInvertTR
→ static int
line 867
// ↓ :invertTR() — fast transpose inverse for rotation+translation ↓
func
matrixGet
→ void
line 1028
// ↓ public helpers used by render.c ↓
cross-refs:modules/render.c:? types/common.h:?
func
matrixPush
→ void
line 1032
cross-refs:modules/render.c:? types/common.h:?
func
matrixIdentity
→ void
line 1036
TODO: does this need to be seperate?
mat3Identity(m);
cross-refs:modules/render.c:? types/common.h:?
func
matrixTransformPoint
→ void
line 1040
cross-refs:modules/render.c:? types/common.h:?
Macros
#define
VANIR
_MODULE MATRIX
line 1
types/quaternion.c
Functions
Lua
lua
quatMul
(number arg2)
line 53
// ↓ __mul: quat * quat — Hamilton product OR quat * scalar ↓
Lua stack args
2numberarg2
lua
quatDiv
(number arg2)
line 77
// ↓ __div: quat / scalar ↓
Lua stack args
2numberarg2
lua
quatSet
(number arg2, number arg3, number arg4, number arg5)
line 106
// ↓ :set(x, y, z, w) — mutates in-place, returns self ↓
Lua stack args
2numberarg2
3numberarg3
4numberarg4
5numberarg5
lua
quatGetMatrix
→ static int
line 198
// ↓ :getMatrix() → Matrix (3x3 rotation matrix) ↓
↓ row-major 3x3, stored as array indices 1..9 ↓
float m[9] = {
1.0f-(yy+zz), xy-wz, xz+wy,
xy+wz, 1.0f-(xx+zz), yz-wx,
xz-wy, yz+wx, 1.0f-(xx+yy)
};
lua
quatSetMatrix
→ static int
line 231
// ↓ :setMatrix(matrix) — sets quat from a 3x3 Matrix, mutates in-place, returns self ↓
↓ Shepperd's method ↓
float trace = m[0] + m[4] + m[8];
lua
quatSetAxisAngle
(number arg3)
line 278
// ↓ :setAxisAngle(axis_vec, degrees) — mutates in-place, returns self ↓
Lua stack args
3numberarg3
lua
quatRotateAroundAxis
(number arg3)
line 325
// ↓ :rotateAroundAxis(axis_vec, degrees) → new Quaternion ↓
Lua stack args
3numberarg3
lua
quatSlerp
(number arg3)
line 451
// ↓ :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
quatLerp
(number arg3)
line 494
// ↓ :lerp(other, t) — linear interpolation, result is normalized ↓
Lua stack args
3numberarg3
lua
quatIndex
(string key)
line 603
// ↓ __index — expose x/y/z/w fields from userdata to Lua ↓
Lua stack args
2stringkey
↓ fall through to method table ↓
indexFallback(L, "vanir.Quaternion", key);
lua
quatNewIndex
(string key, number arg3)
line 621
// ↓ __newindex — allow q.x = n style assignment ↓
Lua stack args
2stringkey
3numberarg3
lua
Quaternion
(number? arg1, number? arg2, number? arg3, number? arg4)
line 683
Lua stack args
1number?arg1
2number?arg2
3number?arg3
4number?arg4
cross-refs:vanir.c:? types/angle.c:? types/common.h:?
C Internal
func
toStringQuat
→ static int
line 24
// ↓ __tostring ↓
func
quatAdd
→ static int
line 33
// ↓ __add ↓
func
quatSub
→ static int
line 43
// ↓ __sub ↓
func
quatUnm
→ static int
line 87
// ↓ __unm ↓
func
quatEq
→ static int
line 96
// ↓ __eq ↓
func
quatSetIdentity
→ static int
line 120
// ↓ :setIdentity() — mutates in-place, returns self ↓
func
quatIsIdentity
→ static int
line 134
// ↓ :isIdentity() ↓
func
quatClone
→ static int
line 143
// ↓ :clone() ↓
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*(q->w*q->x + q->y*q->z), cosR = 1.0f - 2.0f*(q->x*q->x + q->y*q->y);
float sinP = 2.0f*(q->w*q->y - q->z*q->x);
float sinY = 2.0f*(q->w*q->z + q->x*q->y), cosY = 1.0f - 2.0f*(q->y*q->y + q->z*q->z);
func
quatGetAngle
→ static int
line 170
// ↓ :getAngle() → Angle (roll/pitch/yaw in degrees) ↓
func
quatSetAngle
→ static int
line 175
// ↓ :setAngle(angle) — sets quat from Angle (pitch/yaw/roll in degrees), mutates in-place, returns self ↓
func
quatGetAxisAngle
→ static int
line 295
// ↓ :getAxisAngle() → axis_vec, degrees ↓
↓ identity — axis is arbitrary ↓
if (sinHalf > 0.0001f) {
ax = q->x / sinHalf;
ay = q->y / sinHalf;
az = q->z / sinHalf;
} else {
ax = 0.0f;
ay = 0.0f;
az = 1.0f;
}
func
quatDot
→ static int
line 344
// ↓ :dot(other) ↓
func
quatLength
→ static int
line 354
// ↓ :length() — magnitude ↓
func
quatLengthSqr
→ static int
line 363
// ↓ :lengthSqr() ↓
func
quatNormalize
→ static int
line 372
// ↓ :normalize() — mutates in-place, returns self ↓
func
quatGetNormalized
→ static int
line 388
// ↓ :getNormalized() → new Quaternion ↓
func
quatConjugate
→ static int
line 399
// ↓ :conjugate() — mutates in-place, returns self ↓
func
quatGetConjugate
→ static int
line 412
// ↓ :getConjugate() → new Quaternion ↓
func
quatInvert
→ static int
line 421
// ↓ :invert() — full inverse (conjugate / lenSqr), mutates in-place, returns self ↓
func
quatGetInverse
→ static int
line 438
// ↓ :getInverse() → new Quaternion ↓
func
quatRotateVector
→ static int
line 512
// ↓ :rotateVector(vec) → new Vector rotated by this quaternion ↓
↓ t = 2 * cross(q.xyz, v), result = v + q.w * t + cross(q.xyz, t) ↓
float tx = 2.0f*(q->y*iv->z - q->z*iv->y);
float ty = 2.0f*(q->z*iv->x - q->x*iv->z);
float tz = 2.0f*(q->x*iv->y - q->y*iv->x);
func
quatGetForward
→ static int
line 531
// ↓ :getForward() → Vector ↓
↓ rotate (1, 0, 0) by this quaternion ↓
float tx = 0.0f, ty = 2.0f*q->z, tz = -2.0f*q->y;
func
quatGetRight
→ static int
line 547
// ↓ :getRight() → Vector ↓
↓ rotate (0, 1, 0) by this quaternion ↓
float tx = -2.0f*q->z, ty = 0.0f, tz = 2.0f*q->x;
func
quatGetUp
→ static int
line 563
// ↓ :getUp() → Vector ↓
↓ rotate (0, 0, 1) by this quaternion ↓
float tx = 2.0f*q->y, ty = -2.0f*q->x, tz = 0.0f;
func
quatIsZero
→ static int
line 579
// ↓ :isZero() ↓
func
quatRound
→ static int
line 588
// ↓ :round([decimals]) → new Quaternion ↓
Macros
#define
VANIR
_MODULE QUATERNION
line 1
types/texture.c
Functions
Lua
lua
textureMetaGetColor
(integer arg2, integer arg3)
line 90
// ↓ tex:getColor(x, y) → Color ↓
Lua stack args
2integerarg2
3integerarg3
lua
textureGetFloat
(string arg2)
line 174
// ↓ tex:getFloat(key) → number; stub — no float parameter store yet, always returns 0 ↓
Lua stack args
2stringarg2
lua
textureGetInt
(string arg2)
line 184
// ↓ tex:getInt(key) → number; stub — always returns 0 ↓
Lua stack args
2stringarg2
lua
textureGetMatrix
(string arg2)
line 194
// ↓ tex:getMatrix(key) → nil; stub — no matrix parameter store ↓
Lua stack args
2stringarg2
lua
textureGetString
(string key)
line 204
// ↓ tex:getString(key) → string; returns name for "$basetexture", nil for others ↓
Lua stack args
2stringkey
lua
textureGetTextureParm
(string arg2)
line 220
// ↓ tex:getTexture(key) → tex; returns self for "$basetexture" ↓
Lua stack args
2stringarg2
↓ just return self — the caller already has the texture object ↓
lua_pushvalue(L, 1);
lua
textureGetVector
(string arg2)
line 230
// ↓ tex:getVector(key) → Vector | nil; stub ↓
Lua stack args
2stringarg2
lua
textureSetFloat
(string arg2, number arg3)
line 245
// ↓ tex:setFloat(key, value) → nil; stub ↓
Lua stack args
2stringarg2
3numberarg3
lua
textureSetInt
(string arg2, integer arg3)
line 254
// ↓ tex:setInt(key, value) → nil; stub ↓
Lua stack args
2stringarg2
3integerarg3
lua
textureSetMatrix
(string arg2)
line 263
// ↓ tex:setMatrix(key, matrix) → nil; stub ↓
Lua stack args
2stringarg2
lua
textureSetString
(string arg2, string arg3)
line 271
// ↓ tex:setString(key, value) → nil; stub ↓
Lua stack args
2stringarg2
3stringarg3
lua
textureSetTexture
(string arg2)
line 281
// ↓ tex:setTexture(key, tex2) → nil; swaps the underlying GPU data from another texture object ↓ | ↓ currently a stub — in-place GPU data swapping is non-trivial ↓
Lua stack args
2stringarg2
lua
textureSetTextureURL
(string arg2, string arg3)
line 289
// ↓ tex:setTextureURL(key, url) → nil; stub — no HTTP fetching in Vanir ↓
Lua stack args
2stringarg2
3stringarg3
lua
textureSetTextureRenderTarget
(string arg2)
line 298
// ↓ tex:setTextureRenderTarget(key, rt) → nil; stub ↓
Lua stack args
2stringarg2
lua
textureSetUndefined
(string arg2)
line 306
// ↓ tex:setUndefined(key) → nil; clears a parameter; stub ↓
Lua stack args
2stringarg2
lua
textureSetVector
(string arg2)
line 314
// ↓ tex:setVector(key, vec) → nil; stub ↓
Lua stack args
2stringarg2
lua
textureSetImageMeta
(string? path)
line 386
// ↓ 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 9
↓ 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 52
func
textureGetWidth
→ static int
line 62
// ↓ tex:getWidth() → width ↓
func
textureGetHeight
→ static int
line 71
// ↓ tex:getHeight() → height ↓
func
textureGetSize
→ static int
line 80
// ↓ tex:getSize() → width, height ↓
func
textureGetName
→ static int
line 134
// ↓ tex:getName() → string ↓
func
textureGetShader
→ static int
line 144
// ↓ tex:getShader() → string; returns the effective pipeline/shader name for this texture ↓ | ↓ Vanir uses a single built-in textured pipeline, so this always returns "Textured" ↓
func
textureGetKeyValues
→ static int
line 153
// ↓ tex:getKeyValues() → table; returns a table of texture metadata as key-value pairs ↓
func
textureGetVectorLinear
→ static int
line 240
// ↓ tex:getVectorLinear(key) → Vector | nil; stub ↓
func
textureRecompute
→ static int
line 322
// ↓ tex:recompute() → nil; rebuilds GPU bind group from current pixel data ↓
↓ re-upload cpu pixels to the existing gpu texture ↓
extern struct VanirGPU gpu;
func
textureDraw
→ static int
line 351
// ↓ 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 368
// ↓ tex:release() — frees GPU resources and invalidates this object ↓
func
textureDestroyMeta
→ static int
line 380
// ↓ tex:destroy() — alias of release ↓
Externs
extern
gpu
struct VanirGPU gpu
line 329
// ↓ re-upload cpu pixels to the existing gpu texture ↓
types/vector.c
Functions
Lua
lua
vecMul
(number arg1, number arg2)
line 49
// ↓ __mul: vec * scalar or scalar * vec ↓
Lua stack args
1numberarg1
2numberarg2
lua
vecDiv
(number arg2)
line 68
// ↓ __div: vec / scalar ↓
Lua stack args
2numberarg2
lua
vecIsZero
(nil? arg2)
line 217
// ↓ :isZero([tolerance]) ↓
Lua stack args
2nil?arg2
lua
vecIsEqualTol
(number arg3)
line 232
// ↓ :isEqualTol(other, tol) ↓
Lua stack args
3numberarg3
lua
vecMulInPlace
(number arg2)
line 328
// ↓ :mul(scalar) — mutates in-place, returns self ↓
Lua stack args
2numberarg2
lua
vecDivInPlace
(number arg2)
line 342
// ↓ :div(scalar) — mutates in-place, returns self ↓
Lua stack args
2numberarg2
lua
vecSet
(number arg2, number arg3, number arg4)
line 394
// ↓ :set(x, y, z) — mutates in-place, returns self ↓
Lua stack args
2numberarg2
3numberarg3
4numberarg4
lua
vecRotate
(table arg2)
line 430
// ↓ rotate(angle) — rotates vector in-place by Angle using quaternion math ↓
Lua stack args
2tablearg2
↓ build quaternion from Angle (ZYX: yaw(Z), pitch(Y), roll(X)) ↓
float qw, qx, qy, qz;
angToQuat(a, &qw, &qx, &qy, &qz);↓ t = 2 * cross(q.xyz, v), result = v + q.w * t + cross(q.xyz, t) ↓
float tx = 2.0f*(qy*v->z - qz*v->y);
float ty = 2.0f*(qz*v->x - qx*v->z);
float tz = 2.0f*(qx*v->y - qy*v->x);cross-refs:types/common.h:?
lua
vecGetRotated
(table arg2)
line 465
// ↓ :getRotated(angle) → new Vector, does not mutate ↓
Lua stack args
2tablearg2
↓ build quaternion from Angle (ZYX: yaw(Z), pitch(Y), roll(X)) ↓
float qw, qx, qy, qz;
angToQuat(a, &qw, &qx, &qy, &qz);cross-refs:types/common.h:?
lua
vecRotateAroundAxis
(number arg3)
line 499
// ↓ :rotateAroundAxis(axis, degrees) → new Vector ↓
Lua stack args
3numberarg3
lua
vecIndex
(string key)
line 579
// ↓ __index — expose x/y/z fields from userdata to Lua ↓
Lua stack args
2stringkey
↓ fall through to method table ↓
indexFallback(L, "vanir.Vector", key);
lua
vecNewIndex
(string key, number arg3)
line 596
// ↓ __newindex — allow v.x = n style assignment ↓
Lua stack args
2stringkey
3numberarg3
lua
Vector
(number? arg1, number? arg2, number? arg3)
line 667
// ↓ Vector(x, y, z) ↓
Lua stack args
1number?arg1
2number?arg2
3number?arg3
cross-refs:vanir.c:? modules/input.c:? modules/render.c:? types/angle.c:? types/common.h:? types/matrix.c:? types/quaternion.c:? types/texture.c:?
C Internal
func
toStringVec
→ static int
line 20
// ↓ __tostring ↓
func
vecAdd
→ static int
line 29
// ↓ __add ↓
func
vecSub
→ static int
line 39
// ↓ __sub ↓
func
vecUnm
→ static int
line 78
// ↓ __unm ↓
func
vecEq
→ static int
line 87
// ↓ __eq ↓
func
vecLen
→ static int
line 97
// ↓ __len: #vec → magnitude ↓
func
vecDot
→ static int
line 106
// ↓ :dot(other) ↓
func
vecCross
→ static int
line 116
// ↓ :cross(other) → Vector ↓
func
vecGetLength
→ static int
line 130
// ↓ :getLength() ↓
func
vecGetLengthSqr
→ static int
line 135
// ↓ :getLengthSqr() ↓
func
vecGetLength2D
→ static int
line 144
// ↓ :getLength2D() ↓
func
vecGetLength2DSqr
→ static int
line 153
// ↓ :getLength2DSqr() ↓
func
vecGetDistance
→ static int
line 162
// ↓ :getDistance(other) ↓
func
vecGetDistanceSqr
→ static int
line 173
// ↓ :getDistanceSqr(other) ↓
func
vecGetNormalized
→ static int
line 184
// ↓ :getNormalized() → new Vector ↓
func
vecNormalize
→ static int
line 197
// ↓ :normalize() — mutates in-place, returns self ↓
func
vecGetAngle
→ static int
line 247
// ↓ :getAngle() → Angle (pitch/yaw from direction) ↓
func
vecGetAngleEx
→ static int
line 263
// ↓ :getAngleEx(up_vec) → Angle with roll derived from up reference ↓
↓ compute right = forward x up, then actual up = right x forward ↓
float rx = fy*up->z - fz*up->y;
float ry = fz*up->x - fx*up->z;
float rz = fx*up->y - fy*up->x;
func
vecAddInPlace
→ static int
line 300
// ↓ :add(other) — mutates in-place, returns self ↓
func
vecSubInPlace
→ static int
line 314
// ↓ :sub(other) — mutates in-place, returns self ↓
func
vecVmul
→ static int
line 356
// ↓ :vmul(other_vec) — component-wise multiply, returns new Vector ↓
func
vecVdiv
→ static int
line 366
// ↓ :vdiv(other_vec) — component-wise divide, returns new Vector ↓
func
vecSetZero
→ static int
line 376
// ↓ :setZero() — mutates in-place, returns self ↓
func
vecSetX
→ static int
line 389
// ↓ :setX/Y/Z(v) ↓
func
vecSetY
→ static int
line 390
func
vecSetZ
→ static int
line 391
func
vecClone
→ static int
line 407
// ↓ :clone() ↓
func
vecRound
→ static int
line 416
// ↓ :round([decimals]) → new Vector ↓
func
vecGetBasis
→ static int
line 517
// ↓ :getBasis() → forward, right, up (three Vectors) ↓
↓ pick a consistent up reference ↓
float refx = 0.0f, refy = 0.0f, refz = 1.0f;
func
vecWithinAABox
→ static int
line 550
// ↓ :withinAABox(min_vec, max_vec) → bool ↓
func
vecToScreen
→ static int
line 566
// ↓ :toScreen() — projects 3D world pos to 2D screen; stub returning table ↓ | ↓ real implementation would need a camera/projection matrix ↓
↓ without access to the active camera matrices here, return a ↓
↓ table {x=0, y=0, visible=false} as a safe default stub ↓
lua_newtable(L);
setFieldNumber(L, "x", 0.0f);
setFieldNumber(L, "y", 0.0f);
lua_pushboolean(L, 0);
lua_setfield(L, -2, "visible");