mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-09 05:33:42 +00:00
lib: Add frrscript_get_result
Signed-off-by: Donald Lee <dlqs@gmx.com>
This commit is contained in:
parent
24ff8520af
commit
06947ddeac
@ -194,22 +194,31 @@ done:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *frrscript_get_result(struct frrscript *fs,
|
void *frrscript_get_result(struct frrscript *fs, const char *function_name,
|
||||||
const struct frrscript_env *result)
|
const char *name,
|
||||||
|
void *(*lua_to)(lua_State *L, int idx))
|
||||||
{
|
{
|
||||||
void *r;
|
void *p;
|
||||||
struct frrscript_codec c = {.typename = result->typename};
|
struct lua_function_state *lfs;
|
||||||
|
struct lua_function_state lookup = {.name = function_name};
|
||||||
|
|
||||||
struct frrscript_codec *codec = hash_lookup(codec_hash, &c);
|
lfs = hash_lookup(fs->lua_function_hash, &lookup);
|
||||||
assert(codec && "No encoder for type");
|
|
||||||
|
|
||||||
if (!codec->decoder) {
|
if (lfs == NULL) {
|
||||||
zlog_err("No script decoder for type '%s'", result->typename);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* results table is idx 1 on the stack, getfield pushes our item to idx
|
||||||
|
* 2*/
|
||||||
|
lua_getfield(lfs->L, 1, name);
|
||||||
|
if (lua_isnil(lfs->L, -1)) {
|
||||||
|
lua_pop(lfs->L, 1);
|
||||||
|
zlog_err("No result in results table with that name %s", name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
p = lua_to(lfs->L, 2);
|
||||||
|
|
||||||
return r;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void frrscript_register_type_codec(struct frrscript_codec *codec)
|
void frrscript_register_type_codec(struct frrscript_codec *codec)
|
||||||
|
@ -233,8 +233,9 @@ int _frrscript_call_lua(struct lua_function_state *lfs, int nargs);
|
|||||||
* Returns:
|
* Returns:
|
||||||
* The script result of the specified name and type, or NULL.
|
* The script result of the specified name and type, or NULL.
|
||||||
*/
|
*/
|
||||||
void *frrscript_get_result(struct frrscript *fs,
|
void *frrscript_get_result(struct frrscript *fs, const char *function_name,
|
||||||
const struct frrscript_env *result);
|
const char *name,
|
||||||
|
void *(*lua_to)(lua_State *L, int idx));
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user