@@ -434,10 +434,10 @@ pub const Lua = struct {
434
434
return c .lua_getallocf (lua .state , @ptrCast ([* c ]? * anyopaque , data )).? ;
435
435
}
436
436
437
- /// Returns a pointer to a raw memory area associated with the given Lua state
437
+ /// Returns a slice of a raw memory area associated with the given Lua state
438
438
/// The application may use this area for any purpose; Lua does not use it for anything
439
- pub fn getExtraSpace (lua : * Lua ) * anyopaque {
440
- return c .lua_getextraspace (lua .state ).? ;
439
+ pub fn getExtraSpace (lua : * Lua ) [] u8 {
440
+ return @ptrCast ([ * ] u8 , c .lua_getextraspace (lua .state ).? )[0 .. @sizeOf ( isize )] ;
441
441
}
442
442
443
443
/// Pushes onto the stack the value t[key] where t is the value at the given `index`
@@ -2311,6 +2311,17 @@ test "garbage collector" {
2311
2311
try expect (! lua .gc (.set_incremental , .{0 , 0 , 0 }));
2312
2312
}
2313
2313
2314
+ test "extra space" {
2315
+ var lua = try Lua .init (testing .allocator );
2316
+ defer lua .deinit ();
2317
+
2318
+ var space = @ptrCast (* align (1 ) usize , lua .getExtraSpace ().ptr );
2319
+ space .* = 1024 ;
2320
+ // each new thread is initialized with a copy of the extra space from the main thread
2321
+ var thread = lua .newThread ();
2322
+ try expectEqual (@as (usize , 1024 ), @ptrCast (* align (1 ) usize , thread .getExtraSpace ()).* );
2323
+ }
2324
+
2314
2325
test "refs" {
2315
2326
// temporary test that includes a reference to all functions so
2316
2327
// they will be type-checked
@@ -2321,8 +2332,6 @@ test "refs" {
2321
2332
_ = Lua .createTable ;
2322
2333
_ = Lua .dump ;
2323
2334
_ = Lua .raiseError ;
2324
- _ = Lua .gc ;
2325
- _ = Lua .getExtraSpace ;
2326
2335
_ = Lua .getI ;
2327
2336
_ = Lua .getIUserValue ;
2328
2337
_ = Lua .getMetatable ;
0 commit comments