@@ -125,13 +125,38 @@ impl Lua {
125
125
create_lua ( lua_mod)
126
126
}
127
127
128
- /// Loads standard the specified set of the standard libraries into an existing Lua state.
128
+ /// Loads the specified set of safe standard libraries into an existing Lua state.
129
+ ///
130
+ /// Use the [`StdLib`] flags to specifiy the libraries you want to load.
131
+ ///
132
+ /// Note that the `debug` library can't be loaded using this function as it can be used to break
133
+ /// the safety guarantees of rlua. If you really want to load it, use the sister function
134
+ /// [`Lua::unsafe_load_from_std_lib`].
135
+ ///
136
+ /// # Panics
137
+ ///
138
+ /// Panics if `lua_mod` contains `StdLib::DEBUG`
139
+ pub fn load_from_std_lib ( & self , lua_mod : StdLib ) -> Result < ( ) > {
140
+ assert ! (
141
+ !lua_mod. contains( StdLib :: DEBUG ) ,
142
+ "The lua debug module can't be loaded using `load_from_std_lib`. Use `unsafe_load_from_std_lib` instead."
143
+ ) ;
144
+
145
+
146
+ unsafe {
147
+ protect_lua_closure ( self . main_state , 0 , 0 , |state| {
148
+ load_from_std_lib ( state, lua_mod) ;
149
+ } )
150
+ }
151
+ }
152
+
153
+ /// Loads the specified set of standard libraries into an existing Lua state.
129
154
///
130
155
/// Use the [`StdLib`] flags to specifiy the libraries you want to load.
131
156
///
132
157
/// This function is unsafe because it can be used to load the `debug` library which can be used
133
158
/// to break the safety guarantees provided by rlua.
134
- pub unsafe fn load_from_std_lib ( & self , lua_mod : StdLib ) -> Result < ( ) > {
159
+ pub unsafe fn unsafe_load_from_std_lib ( & self , lua_mod : StdLib ) -> Result < ( ) > {
135
160
protect_lua_closure ( self . main_state , 0 , 0 , |state| {
136
161
load_from_std_lib ( state, lua_mod) ;
137
162
} )
0 commit comments