@@ -107,8 +107,6 @@ pub unsafe fn luaL_optstring(L: *mut lua_State, n: c_int, d: *const c_char) -> *
107107 luaL_optlstring ( L , n, d, ptr:: null_mut ( ) )
108108}
109109
110- // Deprecated from 5.3: luaL_checkint, luaL_optint, luaL_checklong, luaL_optlong
111-
112110#[ inline( always) ]
113111pub unsafe fn luaL_typename ( L : * mut lua_State , i : c_int ) -> * const c_char {
114112 lua:: lua_typename ( L , lua:: lua_type ( L , i) )
@@ -138,8 +136,58 @@ pub unsafe fn luaL_getmetatable(L: *mut lua_State, n: *const c_char) {
138136 lua:: lua_getfield_ ( L , lua:: LUA_REGISTRYINDEX , n) ;
139137}
140138
141- // TODO: luaL_opt
139+ #[ inline( always) ]
140+ pub unsafe fn luaL_opt < T > (
141+ L : * mut lua_State ,
142+ f : unsafe extern "C-unwind" fn ( * mut lua_State , c_int ) -> T ,
143+ n : c_int ,
144+ d : T ,
145+ ) -> T {
146+ if lua:: lua_isnoneornil ( L , n) != 0 {
147+ d
148+ } else {
149+ f ( L , n)
150+ }
151+ }
142152
143153//
144- // TODO: Generic Buffer Manipulation
154+ // Generic Buffer Manipulation
145155//
156+
157+ // The buffer size used by the lauxlib buffer system.
158+ // The "16384" workaround is taken from the LuaJIT source code.
159+ #[ rustfmt:: skip]
160+ pub const LUAL_BUFFERSIZE : usize = if libc:: BUFSIZ > 16384 { 8192 } else { libc:: BUFSIZ as usize } ;
161+
162+ #[ repr( C ) ]
163+ pub struct luaL_Buffer {
164+ pub p : * mut c_char , // current position in buffer
165+ pub lvl : c_int , // number of strings in the stack
166+ pub L : * mut lua_State ,
167+ pub buffer : [ c_char ; LUAL_BUFFERSIZE ] ,
168+ }
169+
170+ #[ cfg_attr( all( windows, raw_dylib) , link( name = "lua51" , kind = "raw-dylib" ) ) ]
171+ unsafe extern "C-unwind" {
172+ pub fn luaL_buffinit ( L : * mut lua_State , B : * mut luaL_Buffer ) ;
173+ pub fn luaL_prepbuffer ( B : * mut luaL_Buffer ) -> * mut c_char ;
174+ pub fn luaL_addlstring ( B : * mut luaL_Buffer , s : * const c_char , l : usize ) ;
175+ pub fn luaL_addstring ( B : * mut luaL_Buffer , s : * const c_char ) ;
176+ pub fn luaL_addvalue ( B : * mut luaL_Buffer ) ;
177+ pub fn luaL_pushresult ( B : * mut luaL_Buffer ) ;
178+ }
179+
180+ #[ inline( always) ]
181+ pub unsafe fn luaL_addchar ( B : * mut luaL_Buffer , c : c_char ) {
182+ let buffer_end = ( * B ) . buffer . as_mut_ptr ( ) . add ( LUAL_BUFFERSIZE ) ;
183+ if ( * B ) . p >= buffer_end {
184+ luaL_prepbuffer ( B ) ;
185+ }
186+ * ( * B ) . p = c;
187+ ( * B ) . p = ( * B ) . p . add ( 1 ) ;
188+ }
189+
190+ #[ inline( always) ]
191+ pub unsafe fn luaL_addsize ( B : * mut luaL_Buffer , n : usize ) {
192+ ( * B ) . p = ( * B ) . p . add ( n) ;
193+ }
0 commit comments