pub struct Buffer<'l> {
pub buffer: [c_char; 1024],
/* private fields */
}Expand description
String buffer that allows code to build Lua strings piecemeal.
This structure has a lifetime 'l because it internally stores a pointer to
the Lua State that was used to initialize this buffer.
Fields§
§buffer: [c_char; 1024]Implementations§
Source§impl Buffer<'_>
impl Buffer<'_>
Sourcepub const fn zeroed() -> MaybeUninit<Self>
pub const fn zeroed() -> MaybeUninit<Self>
Construct an instance of Buffer that’s zeroed, and put it inside of
MaybeUninit for future usage.
This actually puts the buffer into an invalid state - it must be used
with luaL_buffinit to properly initialize it.
Only then can it be assumed to be initialized.
Sourcepub unsafe fn new_in_raw(l: *mut State) -> Self
pub unsafe fn new_in_raw(l: *mut State) -> Self
Construct a properly initialized instance of Buffer with the
capacity BUFFER_SIZE in the raw Lua state pointed to by l.
§Safety
l must point to a valid Lua State.
Sourcepub unsafe fn prep_default_with(&mut self, func: impl FnOnce(&mut [c_char]))
pub unsafe fn prep_default_with(&mut self, func: impl FnOnce(&mut [c_char]))
Allocate enough space in the buffer BUFFER_SIZE C characters, and
use a Rust function to fill the space with characters.
See also Buffer::prep_with.
§Safety
The underlying Lua state may raise a memory error.
Sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Get the current length of the buffer.
Equivalent to the C macro luaL_bufflen.
Sourcepub fn contents(&mut self) -> &mut [c_char]
pub fn contents(&mut self) -> &mut [c_char]
Return the current contents of the buffer as a Rust mutable slice.
Functionally equivalent to the C macro luaL_buffaddr.
Sourcepub fn remove(&mut self, delta: usize)
pub fn remove(&mut self, delta: usize)
Remove a given number of C characters from the buffer.
Equivalent to the C macro luaL_buffsub.
Sourcepub unsafe fn add_chars(&mut self, data: &[c_char])
pub unsafe fn add_chars(&mut self, data: &[c_char])
Add an array of C characters to the buffer.
Functionally equivalent to the function luaL_addlstring.
§Safety
The underlying Lua state may raise a memory error.
Sourcepub unsafe fn add_string(&mut self, data: &CStr)
pub unsafe fn add_string(&mut self, data: &CStr)
Add a C string to the buffer.
Equivalent to the function luaL_addstring.
§Safety
The underlying Lua state may raise a memory error.
Sourcepub fn add_value(&mut self)
pub fn add_value(&mut self)
Convert a value on top of the associated Lua stack to a string, and pop the result into the buffer.
Equivalent to the function luaL_addvalue.
Sourcepub fn finish(self)
pub fn finish(self)
Equivalent to the function luaL_pushresult.