Skip to content

Commit e32a8fe

Browse files
committed
docs: update doc comments with links to the Lua manual
1 parent d8a0e0a commit e32a8fe

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

src/ziglua.zig

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,6 @@ pub const Lua = struct {
324324
// the memory allocated by this function should also be aligned for any type that Lua may
325325
// desire to allocate. use the largest alignment for the target
326326
const alignment = @alignOf(std.c.max_align_t);
327-
328-
// the data pointer is an Allocator, so the @alignCast is safe
329327
const allocator = opaqueCast(Allocator, data.?);
330328

331329
if (@ptrCast(?[*]align(alignment) u8, @alignCast(alignment, ptr))) |prev_ptr| {
@@ -376,65 +374,81 @@ pub const Lua = struct {
376374
// Library functions are included in alphabetical order.
377375
// Each is kept similar to the original C API function while also making it easy to use from Zig
378376

379-
/// Converts the acceptable index `index` into an equivalent absolute index
377+
/// Returns the acceptable index index converted into an equivalent absolute index
378+
/// See https://www.lua.org/manual/5.4/manual.html#lua_absindex
380379
pub fn absIndex(lua: *Lua, index: i32) i32 {
381380
return c.lua_absindex(lua.state, index);
382381
}
383382

384-
/// Performs an arithmetic or bitwise operation over the value(s) at the top of the stack
385-
/// This function follows the semantics of the corresponding Lua operator
383+
/// Performs an arithmetic or bitwise operation over the value(s) at the top of the stack,
384+
/// with the value at the top being the second operand. Pushes the result of the operation.
385+
/// This function follows the semantics of the corresponding Lua operator and may call metamethods
386+
/// See https://www.lua.org/manual/5.4/manual.html#lua_arith
386387
pub fn arith(lua: *Lua, op: ArithOperator) void {
387388
c.lua_arith(lua.state, @enumToInt(op));
388389
}
389390

390391
/// Sets a new panic function and returns the old one
392+
/// See https://www.lua.org/manual/5.4/manual.html#lua_atpanic
391393
pub fn atPanic(lua: *Lua, panic_fn: CFn) ?CFn {
392394
return c.lua_atpanic(lua.state, panic_fn);
393395
}
394396

395397
/// Calls a function (or any callable value)
398+
/// First push the function to be called onto the stack. Then push any arguments onto the stack.
399+
/// Then call this function. All arguments and the function value are popped, and any results
400+
/// are pushed onto the stack.
401+
/// See https://www.lua.org/manual/5.4/manual.html#lua_call
396402
pub fn call(lua: *Lua, num_args: i32, num_results: i32) void {
397403
lua.callCont(num_args, num_results, 0, null);
398404
}
399405

400-
/// Like `call`, but allows the called function to yield
406+
/// Like call, but allows the called function to yield
407+
/// See https://www.lua.org/manual/5.4/manual.html#lua_callk
401408
pub fn callCont(lua: *Lua, num_args: i32, num_results: i32, ctx: Context, k: ?CContFn) void {
402409
c.lua_callk(lua.state, num_args, num_results, ctx, k);
403410
}
404411

405-
/// Ensures that the stack has space for at least `n` extra arguments
406-
/// Returns an error if it cannot fulfil the request
412+
/// Ensures that the stack has space for at least n extra arguments
413+
/// Returns an error if more stack space cannot be allocated
407414
/// Never shrinks the stack
415+
/// See https://www.lua.org/manual/5.4/manual.html#lua_checkstack
408416
pub fn checkStack(lua: *Lua, n: i32) !void {
409417
if (c.lua_checkstack(lua.state, n) == 0) return error.Fail;
410418
}
411419

412420
/// Release all Lua objects in the state and free all dynamic memory
421+
/// See https://www.lua.org/manual/5.4/manual.html#lua_close
413422
pub fn close(lua: *Lua) void {
414423
c.lua_close(lua.state);
415424
}
416425

417-
/// Close the to-be-closed slot at the given `index` and set the value to nil
426+
/// Close the to-be-closed slot at the given index and set the value to nil
427+
/// The index must be the last index previously marked to be closed with toClose
428+
/// See https://www.lua.org/manual/5.4/manual.html#lua_closeslot
418429
pub fn closeSlot(lua: *Lua, index: i32) void {
419430
c.lua_closeslot(lua.state, index);
420431
}
421432

422433
/// Compares two Lua values
423-
/// Returns true if the value at `index1` satisfies `op` when compared with the value at `index2`
434+
/// Returns true if the value at index1 satisisfies the comparison with the value at index2
424435
/// Returns false otherwise, or if any index is not valid
436+
/// See https://www.lua.org/manual/5.4/manual.html#lua_compare
425437
pub fn compare(lua: *Lua, index1: i32, index2: i32, op: CompareOperator) bool {
426438
// TODO: perhaps support gt/ge by swapping args...
427439
return c.lua_compare(lua.state, index1, index2, @enumToInt(op)) != 0;
428440
}
429441

430-
/// Concatenates the `n` values at the top of the stack, pops them, and leaves the result at the top
431-
/// If `n` is 1, the result is a single value on the stack (nothing changes)
432-
/// If `n` is 0, the result is the empty string
442+
/// Concatenates the n values at the top of the stack, pops them, and leaves the result at the top
443+
/// If the number of values is 1, the result is a single value on the stack (nothing changes)
444+
/// If the number of values is 0, the result is the empty string
445+
/// See https://www.lua.org/manual/5.4/manual.html#lua_concat
433446
pub fn concat(lua: *Lua, n: i32) void {
434447
c.lua_concat(lua.state, n);
435448
}
436449

437-
/// Copies the element at `from_index` to the valid index `to_index`, replacing the value at that position
450+
/// Copies the element at from_index to the valid index to_index, replacing the value at that position
451+
/// See https://www.lua.org/manual/5.4/manual.html#lua_copy
438452
pub fn copy(lua: *Lua, from_index: i32, to_index: i32) void {
439453
c.lua_copy(lua.state, from_index, to_index);
440454
}

0 commit comments

Comments
 (0)