| 2995 | } |
| 2996 | |
| 2997 | static int get_func_by_ref(Lua L, const char *entry, char **err) |
| 2998 | { |
| 2999 | // return function to call on the lua stack |
| 3000 | lua_getglobal(L, "_SP"); |
| 3001 | lua_pushstring(L, "cdb2_func_refs"); |
| 3002 | lua_gettable(L, -2); // result, _SP{} |
| 3003 | if (!lua_istable(L, -1)) { |
| 3004 | goto bad; |
| 3005 | } |
| 3006 | lua_remove(L, 1); // _SP{} |
| 3007 | lua_pushstring(L, entry); |
| 3008 | lua_gettable(L, -2); |
| 3009 | if (!lua_isfunction(L, -1)) { |
| 3010 | goto bad; |
| 3011 | } |
| 3012 | lua_remove(L, 1); // cdb2_func_refs |
| 3013 | // return with function on stack |
| 3014 | return 0; |
| 3015 | |
| 3016 | bad: |
| 3017 | // return with nothing on the stack |
| 3018 | lua_settop(L, 0); |
| 3019 | *err = strdup("get_func_by_ref failed"); |
| 3020 | return -1; |
| 3021 | } |
| 3022 | |
| 3023 | // return 'main' function to call on the lua stack |
| 3024 | static int get_func_by_name(Lua L, const char *func, char **err) |
nothing calls this directly
no test coverage detected