pub(crate) fn lua_map(
    webnis: &Webnis,
    funcname: &str,
    domain: &str,
    keyname: &str,
    keyvalue: &str,
) -> Result<serde_json::Value, WnError>
{
    LUA.with(|lua_tls| {
        let mut lua_state = lua_tls.borrow();
        if !lua_state.did_init {
            drop(lua_state);
            let mut lua_state_mut = lua_tls.borrow_mut();
	        let webnis = webnis.clone();
            lua_state_mut.lua.context(|ctx| set_webnis_global(ctx, webnis));
            lua_state_mut.did_init = true;
            drop(lua_state_mut);
            lua_state = lua_tls.borrow();
        }

        lua_state.lua.context(|ctx| {
            // create Request.
            let req = Request{
                domain:     domain.to_string(),
                keyname:    Some(keyname.to_string()),
                keyvalue:   Some(keyvalue.to_string()),
                ..Request::default()
            };

            // find the lua function we need to call by name.
            let func: Function = match ctx.globals().get(funcname) {
                Ok(f) => f,
                Err(_e) => return Err(WnError::LuaFunctionNotFound),
            };

            // Call the function
            let val = match func.call::<_, rlua::Value>(req) {
                Ok(v) => v,
                Err(e) => {
                    merror!("lua_map: executing {}:\n{}", funcname, e);
                    return Err(WnError::LuaError);
                },
            };

            let jv = lua_value_to_json(val);
            Ok(jv)
        })
    })
}
/// lua_map calls a lua function. The return value is usually a map, or nil.
lua_map calls a lua function. The return value is usually a map, or nil.
lua_map calls a lua function . The return value is usually a map or nil .
pub(crate) fn lua_map(
    webnis: &Webnis,
    funcname: &str,
    domain: &str,
    keyname: &str,
    keyvalue: &str,
) -> Result<serde_json::Value, WnError>
{
    LUA.with(|lua_tls| {
        let mut lua_state = lua_tls.borrow();
        if !lua_state.did_init {
            drop(lua_state);
            let mut lua_state_mut = lua_tls.borrow_mut();
	        let webnis = webnis.clone();
            lua_state_mut.lua.context(|ctx| set_webnis_global(ctx, webnis));
            lua_state_mut.did_init = true;
            drop(lua_state_mut);
            lua_state = lua_tls.borrow();
        }
        lua_state.lua.context(|ctx| {
            // create Request.
            let req = Request{
                domain:     domain.to_string(),
                keyname:    Some(keyname.to_string()),
                keyvalue:   Some(keyvalue.to_string()),
                ..Request::default()
            };
            // find the lua function we need to call by name.
            let func: Function = match ctx.globals().get(funcname) {
                Ok(f) => f,
                Err(_e) => return Err(WnError::LuaFunctionNotFound),
            };
            // Call the function
            let val = match func.call::<_, rlua::Value>(req) {
                Ok(v) => v,
                Err(e) => {
                    merror!("lua_map: executing {}:\n{}", funcname, e);
                    return Err(WnError::LuaError);
                },
            };
            let jv = lua_value_to_json(val);
            Ok(jv)
        })
    })
}
pub ( crate ) fn lua_map ( webnis : & Webnis , funcname : & str , domain : & str , keyname : & str , keyvalue : & str , ) -> Result < serde_json :: Value , WnError > { LUA . with ( | lua_tls | { let mut lua_state = lua_tls . borrow ( ) ; if ! lua_state . did_init { drop ( lua_state ) ; let mut lua_state_mut = lua_tls . borrow_mut ( ) ; let webnis = webnis . clone ( ) ; lua_state_mut . lua . context ( | ctx | set_webnis_global ( ctx , webnis ) ) ; lua_state_mut . did_init = true ; drop ( lua_state_mut ) ; lua_state = lua_tls . borrow ( ) ; } lua_state . lua . context ( | ctx | { // create Request. let req = Request { domain : domain . to_string ( ) , keyname : Some ( keyname . to_string ( ) ) , keyvalue : Some ( keyvalue . to_string ( ) ) , .. Request :: default ( ) } ; // find the lua function we need to call by name. let func : Function = match ctx . globals ( ) . get ( funcname ) { Ok ( f ) => f , Err ( _e ) => return Err ( WnError :: LuaFunctionNotFound ) , } ; // Call the function let val = match func . call :: < _ , rlua :: Value > ( req ) { Ok ( v ) => v , Err ( e ) => { merror ! ( " \n " funcname e ) ; return Err ( WnError :: LuaError ) ; } , } ; let jv = lua_value_to_json ( val ) ; Ok ( jv ) } ) } ) }
lua_map calls a lua function.
lua_map calls a lua function .
webnis
&Webnis
funcname
&str
domain
&str
keyname
&str
keyvalue
&str