mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-06 10:54:47 +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;
|
||||
}
|
||||
|
||||
void *frrscript_get_result(struct frrscript *fs,
|
||||
const struct frrscript_env *result)
|
||||
void *frrscript_get_result(struct frrscript *fs, const char *function_name,
|
||||
const char *name,
|
||||
void *(*lua_to)(lua_State *L, int idx))
|
||||
{
|
||||
void *r;
|
||||
struct frrscript_codec c = {.typename = result->typename};
|
||||
void *p;
|
||||
struct lua_function_state *lfs;
|
||||
struct lua_function_state lookup = {.name = function_name};
|
||||
|
||||
struct frrscript_codec *codec = hash_lookup(codec_hash, &c);
|
||||
assert(codec && "No encoder for type");
|
||||
lfs = hash_lookup(fs->lua_function_hash, &lookup);
|
||||
|
||||
if (!codec->decoder) {
|
||||
zlog_err("No script decoder for type '%s'", result->typename);
|
||||
if (lfs == 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)
|
||||
|
@ -233,8 +233,9 @@ int _frrscript_call_lua(struct lua_function_state *lfs, int nargs);
|
||||
* Returns:
|
||||
* The script result of the specified name and type, or NULL.
|
||||
*/
|
||||
void *frrscript_get_result(struct frrscript *fs,
|
||||
const struct frrscript_env *result);
|
||||
void *frrscript_get_result(struct frrscript *fs, const char *function_name,
|
||||
const char *name,
|
||||
void *(*lua_to)(lua_State *L, int idx));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user