@@ -324,8 +324,6 @@ pub const Lua = struct {
324
324
// the memory allocated by this function should also be aligned for any type that Lua may
325
325
// desire to allocate. use the largest alignment for the target
326
326
const alignment = @alignOf (std .c .max_align_t );
327
-
328
- // the data pointer is an Allocator, so the @alignCast is safe
329
327
const allocator = opaqueCast (Allocator , data .? );
330
328
331
329
if (@ptrCast (? [* ]align (alignment ) u8 , @alignCast (alignment , ptr ))) | prev_ptr | {
@@ -376,65 +374,81 @@ pub const Lua = struct {
376
374
// Library functions are included in alphabetical order.
377
375
// Each is kept similar to the original C API function while also making it easy to use from Zig
378
376
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
380
379
pub fn absIndex (lua : * Lua , index : i32 ) i32 {
381
380
return c .lua_absindex (lua .state , index );
382
381
}
383
382
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
386
387
pub fn arith (lua : * Lua , op : ArithOperator ) void {
387
388
c .lua_arith (lua .state , @enumToInt (op ));
388
389
}
389
390
390
391
/// Sets a new panic function and returns the old one
392
+ /// See https://www.lua.org/manual/5.4/manual.html#lua_atpanic
391
393
pub fn atPanic (lua : * Lua , panic_fn : CFn ) ? CFn {
392
394
return c .lua_atpanic (lua .state , panic_fn );
393
395
}
394
396
395
397
/// 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
396
402
pub fn call (lua : * Lua , num_args : i32 , num_results : i32 ) void {
397
403
lua .callCont (num_args , num_results , 0 , null );
398
404
}
399
405
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
401
408
pub fn callCont (lua : * Lua , num_args : i32 , num_results : i32 , ctx : Context , k : ? CContFn ) void {
402
409
c .lua_callk (lua .state , num_args , num_results , ctx , k );
403
410
}
404
411
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
407
414
/// Never shrinks the stack
415
+ /// See https://www.lua.org/manual/5.4/manual.html#lua_checkstack
408
416
pub fn checkStack (lua : * Lua , n : i32 ) ! void {
409
417
if (c .lua_checkstack (lua .state , n ) == 0 ) return error .Fail ;
410
418
}
411
419
412
420
/// 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
413
422
pub fn close (lua : * Lua ) void {
414
423
c .lua_close (lua .state );
415
424
}
416
425
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
418
429
pub fn closeSlot (lua : * Lua , index : i32 ) void {
419
430
c .lua_closeslot (lua .state , index );
420
431
}
421
432
422
433
/// 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
424
435
/// Returns false otherwise, or if any index is not valid
436
+ /// See https://www.lua.org/manual/5.4/manual.html#lua_compare
425
437
pub fn compare (lua : * Lua , index1 : i32 , index2 : i32 , op : CompareOperator ) bool {
426
438
// TODO: perhaps support gt/ge by swapping args...
427
439
return c .lua_compare (lua .state , index1 , index2 , @enumToInt (op )) != 0 ;
428
440
}
429
441
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
433
446
pub fn concat (lua : * Lua , n : i32 ) void {
434
447
c .lua_concat (lua .state , n );
435
448
}
436
449
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
438
452
pub fn copy (lua : * Lua , from_index : i32 , to_index : i32 ) void {
439
453
c .lua_copy (lua .state , from_index , to_index );
440
454
}
0 commit comments