@@ -11,6 +11,7 @@ macro_rules! dyn_symbols {
1111 $( #[ $outer: meta] ) *
1212 $vis: vis extern $abi: literal fn $name: ident ( $( $arg: ident : $argty: ty) ,* $( , ) ? ) -> $ret: ty; $( $rest: tt) *
1313 ) => {
14+ $( #[ $outer] ) *
1415 pub static $name: Lazy <extern $abi fn ( $( $arg: $argty) ,* ) -> $ret> = Lazy :: new( || unsafe {
1516 std:: mem:: transmute( LUA_SHARED_RAW . get:: <extern $abi fn ( $( $argty) ,* ) -> $ret>( stringify!( $name) . as_bytes( ) ) . unwrap( ) )
1617 } ) ;
@@ -26,6 +27,7 @@ macro_rules! lua_macros {
2627 $vis: vis fn $name: ident ( $( $arg: ident : $argty: ty) ,* $( , ) ? ) -> $ret: ty $body: block; $( $rest: tt) *
2728 ) => {
2829 #[ inline( always) ]
30+ $( #[ $outer] ) *
2931 $vis fn $name( $( $arg: $argty) ,* ) -> $ret $body
3032 lua_macros!( $( $rest) * ) ;
3133 } ;
@@ -35,8 +37,6 @@ macro_rules! lua_macros {
3537
3638// Create Lazy cells that'll find the functions at runtime when called.
3739dyn_symbols ! {
38- pub extern "system" fn CreateInterface ( pName: LuaString , pReturnCode: * mut c_int) -> * mut c_void;
39-
4040 pub extern "C" fn luaL_loadbufferx(
4141 L : LuaState ,
4242 code: LuaString ,
@@ -110,7 +110,10 @@ dyn_symbols! {
110110 pub extern "C" fn lua_pushinteger( L : LuaState , n: LuaInteger ) -> ( ) ;
111111
112112 // Type checking getters
113+ /// Same as luaL_checknumber, but casts it to an integer.
113114 pub extern "C" fn luaL_checkinteger( L : LuaState , narg: c_int) -> LuaInteger ;
115+ /// Checks whether the value at stack index 'narg' is a number and returns this number.
116+ /// If it is not a lua number, will throw an error to Lua.
114117 pub extern "C" fn luaL_checknumber( L : LuaState , narg: c_int) -> LuaNumber ;
115118 pub extern "C" fn luaL_checklstring( L : LuaState , narg: c_int, len: SizeT ) -> LuaString ;
116119
@@ -125,7 +128,9 @@ dyn_symbols! {
125128 pub extern "C" fn lua_createtable( L : LuaState , narr: c_int, nrec: c_int) -> ( ) ;
126129
127130 // Destruction
128- pub extern "C" fn lua_close( L : LuaState ) -> ( ) ; // Destroys the lua state
131+ /// Destroys the given lua state.
132+ /// You *probably* don't want to do this, unless you just want to self destruct the server / your client.
133+ pub extern "C" fn lua_close( L : LuaState ) -> ( ) ;
129134
130135 // JIT
131136 // Returns 1 for success, 0 for failure
@@ -148,6 +153,8 @@ dyn_symbols! {
148153 // Coroutines
149154 pub extern "C" fn lua_yield( L : LuaState , nresults: c_int) -> c_int;
150155 pub extern "C" fn lua_status( L : LuaState ) -> c_int;
156+ /// Starts and resumes a coroutine in a given thread.
157+ /// Blame garry for the _real
151158 pub extern "C" fn lua_resume_real( L : LuaState , narg: c_int) -> c_int;
152159
153160 // Comparison
@@ -161,22 +168,32 @@ dyn_symbols! {
161168 pub extern "C" fn lua_error( L : LuaState ) -> c_int;
162169
163170 // Libraries
171+ /// Opens the standard 'table' library for a lua state
164172 pub extern "C" fn luaopen_table( L : LuaState ) -> c_int;
173+ /// Opens the standard 'string' library for a lua state
165174 pub extern "C" fn luaopen_string( L : LuaState ) -> c_int;
175+ /// Opens the standard 'package' library for a lua state
166176 pub extern "C" fn luaopen_package( L : LuaState ) -> c_int;
177+ /// Opens the standard 'os' library for a lua state
167178 pub extern "C" fn luaopen_os( L : LuaState ) -> c_int;
179+ /// Opens the standard 'table' library for a lua state
168180 pub extern "C" fn luaopen_math( L : LuaState ) -> c_int;
181+ /// Opens the standard 'table' library for a lua state
169182 pub extern "C" fn luaopen_jit( L : LuaState ) -> c_int;
183+ /// Opens the standard 'table' library for a lua state
170184 pub extern "C" fn luaopen_debug( L : LuaState ) -> c_int;
185+ /// Opens the standard 'table' library for a lua state
171186 pub extern "C" fn luaopen_bit( L : LuaState ) -> c_int;
187+ /// Opens the standard 'table' library for a lua state
172188 pub extern "C" fn luaopen_base( L : LuaState ) -> c_int;
189+ /// Opens the standard 'table' library for a lua state
173190 pub extern "C" fn luaL_openlibs( L : LuaState ) -> ( ) ;
191+ /// Internally called by luaL_register, opens given list of LuaRegs with number of functions provided explicitly
174192 pub extern "C" fn luaL_openlib( L : LuaState , libname: LuaString , l: * const LuaReg , nup: c_int) -> ( ) ;
175193
176- /// luaL_register
177194 /// When called with libname as nullptr, it simply registers all functions in the list l reg! into the table on the top of the stack.
178195 /// # Example
179- /// ```rust
196+ /// ```rust, ignore
180197 /// let lib = reg! [
181198 /// "my_function" => my_function,
182199 /// "my_other_function" => my_other_function,
@@ -226,6 +243,7 @@ dyn_symbols! {
226243 ) -> LuaString ;
227244
228245 pub extern "C" fn lua_checkstack( L : LuaState , extra: c_int) -> c_int;
246+ /// Sets the error handler for the lua state.
229247 pub extern "C" fn lua_atpanic( L : LuaState , panicf: LuaCFunction ) -> LuaCFunction ;
230248 pub extern "C" fn lua_gettop( L : LuaState ) -> c_int;
231249 pub extern "C" fn lua_remove( L : LuaState , index: c_int) -> ( ) ;
@@ -235,39 +253,51 @@ dyn_symbols! {
235253 pub extern "C" fn luaL_prepbuffer( b: * mut LuaBuffer ) -> * mut i8 ;
236254
237255 // String methods
256+ /// Creates a copy of string 's' by replacing any occurrence of the string 'p' with the string 'r'
257+ /// Pushes the resulting string on the stack and returns it
238258 pub extern "C" fn luaL_gsub( s: LuaString , pattern: LuaString , replace: LuaString ) -> LuaString ;
239259}
240260
241261// Inline functions to mirror the C macros that come with the lua api
242262lua_macros ! {
263+ /// Pops n elements from the lua stack.
243264 pub fn lua_pop( L : LuaState , ind: c_int) -> ( ) {
244265 lua_settop( L , -( ind) - 1 ) ;
245266 } ;
246267
268+ /// Gets a value from _G
269+ /// Internally calls lua_getfield with [crate::globals::Lua::GLOBALSINDEX]
247270 pub fn lua_getglobal( L : LuaState , name: LuaString ) -> ( ) {
248271 lua_getfield( L , GLOBALSINDEX , name) ;
249272 } ;
250273
274+ /// Sets a value in _G
275+ /// Internally calls lua_setfield with [crate::globals::Lua::GLOBALSINDEX]
251276 pub fn lua_setglobal( L : LuaState , name: LuaString ) -> ( ) {
252277 lua_setfield( L , GLOBALSINDEX , name) ;
253278 } ;
254279
280+ /// Pushes a "C" function to the stack
255281 pub fn lua_pushcfunction( L : LuaState , fnc: LuaCFunction ) -> ( ) {
256282 lua_pushcclosure( L , fnc, 0 ) ;
257283 } ;
258284
285+ /// Equivalent to lua_tolstring with len equal to 0
259286 pub fn lua_tostring( L : LuaState , idx: c_int) -> LuaString {
260287 lua_tolstring( L , idx, 0 )
261288 } ;
262289
290+ /// Starts and resumes a coroutine in a given thread
263291 pub fn lua_resume( L : LuaState , narg: c_int) -> c_int {
264292 lua_resume_real( L , narg)
265293 } ;
266294
295+ /// Returns if the value at the given index is a C or Lua function.
267296 pub fn lua_isfunction( L : LuaState , n: c_int) -> bool {
268297 lua_type( L , n) == Lua :: Type :: Function
269298 } ;
270299
300+ /// Returns if the value at the given index is a table.
271301 pub fn lua_istable( L : LuaState , n: c_int) -> bool {
272302 lua_type( L , n) == Lua :: Type :: Table
273303 } ;
@@ -276,44 +306,59 @@ lua_macros! {
276306 lua_type( L , n) == Lua :: Type :: LUserData
277307 } ;
278308
309+ /// Returns if the value at the given index is nil.
310+ /// You might want to use [lua_isnoneornil] instead.
279311 pub fn lua_isnil( L : LuaState , n: c_int) -> bool {
280312 lua_type( L , n) == Lua :: Type :: Nil
281313 } ;
282314
315+ /// Returns if the value at the given index is a boolean.
283316 pub fn lua_isboolean( L : LuaState , n: c_int) -> bool {
284317 lua_type( L , n) == Lua :: Type :: Bool
285318 } ;
286319
320+ /// Returns if the value at the given index is a thread.
287321 pub fn lua_isthread( L : LuaState , n: c_int) -> bool {
288322 lua_type( L , n) == Lua :: Type :: Thread
289323 } ;
290324
325+ /// Returns if the value at the given index is none (element outside of stack / invalid)
291326 pub fn lua_isnone( L : LuaState , n: c_int) -> bool {
292327 lua_type( L , n) == Lua :: Type :: None
293328 } ;
294329
330+ /// Returns if the value at the given index is none (invalid) or nil.
295331 pub fn lua_isnoneornil( L : LuaState , n: c_int) -> bool {
296332 lua_type( L , n) <= 0
297333 } ;
298334
335+ /// Loads and pcalls a string of lua code
336+ /// Returns if the code was successfully executed
337+ /// Error will be left on the stack if the code failed to execute
299338 pub fn luaL_dostring( L : LuaState , str : LuaString ) -> bool {
300339 luaL_loadstring( L , str ) == 0 || lua_pcall( L , 0 , Lua :: MULTRET , 0 ) == 0
301340 } ;
302341
342+ /// Loads and pcalls a file's lua code
343+ /// Returns if the code was successfully executed
344+ /// Error will be left on the stack if the code failed to execute
303345 pub fn luaL_dofile( L : LuaState , filename: LuaString ) -> bool {
304346 luaL_loadfile( L , filename) == 0 || lua_pcall( L , 0 , Lua :: MULTRET , 0 ) == 0
305347 } ;
306348
349+ /// Returns value at [crate::globals::Lua::REGISTRYINDEX] with name 'name'
307350 pub fn luaL_getmetatable( L : LuaState , name: LuaString ) -> ( ) {
308351 lua_getfield( L , Lua :: REGISTRYINDEX , name) ;
309352 } ;
310353
354+ /// If a condition is false, throws an argument error at numarg
311355 pub fn luaL_argcheck( L : LuaState , cond: bool , numarg: c_int, extramsg: LuaString ) -> ( ) {
312356 if !cond {
313357 luaL_argerror( L , numarg, extramsg) ;
314358 }
315359 } ;
316360
361+ /// Returns the type name of object at index i
317362 pub fn luaL_typename( L : LuaState , i: c_int) -> LuaString {
318363 lua_typename( L , lua_type( L , i) )
319364 } ;
0 commit comments