@@ -188,7 +188,11 @@ struct LuaJsonMapIter {
188188    iter :  serde_json:: map:: Iter < ' this > , 
189189} 
190190
191- fn  decode ( lua :  & Lua ,  ( data,  opts) :  ( StringOrBytes ,  Option < Table > ) )  -> Result < StdResult < Value ,  String > >  { 
191+ /// Decodes a JSON string or bytes into a Lua value. 
192+ /// 
193+ /// The optional `opts` table can contain: 
194+ /// - `set_array_metatable` (boolean): If true, sets a metatable for arrays. Default is false. 
195+ pub  fn  decode ( lua :  & Lua ,  ( data,  opts) :  ( StringOrBytes ,  Option < Table > ) )  -> Result < StdResult < Value ,  String > >  { 
192196    let  opts = opts. as_ref ( ) ; 
193197    let  mut  options = SerializeOptions :: new ( ) ; 
194198    if  let  Some ( enabled)  = opts. and_then ( |t| t. get :: < bool > ( "set_array_metatable" ) . ok ( ) )  { 
@@ -199,20 +203,28 @@ fn decode(lua: &Lua, (data, opts): (StringOrBytes, Option<Table>)) -> Result<Std
199203    Ok ( Ok ( lua. to_value_with ( & json,  options) ?) ) 
200204} 
201205
202- fn  decode_native ( lua :  & Lua ,  data :  StringOrBytes )  -> Result < StdResult < Value ,  String > >  { 
206+ /// Decodes a JSON string or bytes as a native Rust object. 
207+ /// 
208+ /// The returned value can be a primitive type or userdata. 
209+ pub  fn  decode_native ( lua :  & Lua ,  data :  StringOrBytes )  -> Result < StdResult < Value ,  String > >  { 
203210    let  json:  serde_json:: Value  = lua_try ! ( serde_json:: from_slice( & data. as_bytes_deref( ) ) ) ; 
204211    Ok ( Ok ( lua_try ! ( JsonObject :: from( json) . into_lua( lua) ) ) ) 
205212} 
206213
207- fn  encode ( value :  Value ,  options :  Option < Table > )  -> StdResult < String ,  String >  { 
214+ /// Encodes a Lua value into a JSON string. 
215+ /// 
216+ /// The optional `opts` table can contain: 
217+ /// - `pretty` (boolean): If true, pretty formats the JSON string. Default is false. 
218+ /// - `relaxed` (boolean): If true, skip recursive tables and unsupported types. Default is false. 
219+ pub  fn  encode ( value :  Value ,  opts :  Option < Table > )  -> StdResult < String ,  String >  { 
208220    let  mut  value = value. to_serializable ( ) ; 
209-     let  options  = options . as_ref ( ) ; 
221+     let  opts  = opts . as_ref ( ) ; 
210222
211-     if  options . and_then ( |t| t. get :: < bool > ( "relaxed" ) . ok ( ) )  == Some ( true )  { 
223+     if  opts . and_then ( |t| t. get :: < bool > ( "relaxed" ) . ok ( ) )  == Some ( true )  { 
212224        value = value. deny_recursive_tables ( false ) . deny_unsupported_types ( false ) ; 
213225    } 
214226
215-     if  options . and_then ( |t| t. get :: < bool > ( "pretty" ) . ok ( ) )  == Some ( true )  { 
227+     if  opts . and_then ( |t| t. get :: < bool > ( "pretty" ) . ok ( ) )  == Some ( true )  { 
216228        value = value. sort_keys ( true ) ; 
217229        return  serde_json:: to_string_pretty ( & value) . map_err ( |e| e. to_string ( ) ) ; 
218230    } 
0 commit comments