get optional string value from table. return value must be freed by caller. */
| 1052 | /* get optional string value from table. |
| 1053 | return value must be freed by caller. */ |
| 1054 | char * |
| 1055 | get_table_str_opt(lua_State *L, const char *name, char *defval) |
| 1056 | { |
| 1057 | const char *ret; |
| 1058 | int ltyp; |
| 1059 | |
| 1060 | lua_getfield(L, -1, name); |
| 1061 | ltyp = lua_type(L, -1); |
| 1062 | if (ltyp == LUA_TSTRING || ltyp == LUA_TNIL) { |
| 1063 | ret = luaL_optstring(L, -1, defval); |
| 1064 | } else if (ltyp == LUA_TFUNCTION) { |
| 1065 | nhl_pcall_handle(L, 0, 1, "get_table_str_opt", NHLpa_panic); |
| 1066 | ret = luaL_optstring(L, -1, defval); |
| 1067 | } else { |
| 1068 | nhl_error(L, "get_table_str_opt: no string"); |
| 1069 | } |
| 1070 | if (ret) { |
| 1071 | lua_pop(L, 1); |
| 1072 | return dupstr(ret); |
| 1073 | } |
| 1074 | lua_pop(L, 1); |
| 1075 | return NULL; |
| 1076 | } |
| 1077 | |
| 1078 | int |
| 1079 | get_table_boolean(lua_State *L, const char *name) |
no test coverage detected