@@ 0,0 1,65 @@
+/*
+ * Copyright (c) 2024 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "xlua_impl.h"
+#include <hlog/iso3166.h>
+
+/* return a continent string or nil [-1,+1,-] */
+static int xlua_lookup_continent(lua_State *L)
+{
+ int nargs = lua_gettop(L);
+ const char *cont;
+
+ xlua_checkstack(L, 1, 1, 1);
+
+ if (lua_isnil(L, -1)) {
+ cont = NULL;
+ } else {
+ const char *cc;
+
+ cc = luaL_checkstring(L, -1);
+
+ cont = iso3166_lookup_continent(cc);
+ }
+
+ lua_pop(L, 1);
+
+ if (!cont)
+ lua_pushnil(L);
+ else
+ lua_pushstring(L, cont);
+
+ ASSERT3S(nargs, ==, lua_gettop(L));
+
+ return 1;
+}
+
+static const luaL_Reg iso3166_funcs[] = {
+ { "lookup_continent", xlua_lookup_continent },
+ { NULL, NULL },
+};
+
+/* register the sig library [-0,+0,e] */
+void xlua_pushlib_iso3166(lua_State *L)
+{
+ luaL_newlib(L, iso3166_funcs);
+}
@@ 80,6 80,10 @@ static void xlua_register(lua_State *L)
xlua_pushlib_index(L);
lua_settable(L, -3);
+ lua_pushliteral(L, "iso3166");
+ xlua_pushlib_iso3166(L);
+ lua_settable(L, -3);
+
lua_pushliteral(L, "nvl");
xlua_pushlib_nvl(L);
lua_settable(L, -3);
@@ 1,5 1,5 @@
/*
- * Copyright (c) 2020-2023 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2020-2024 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ 37,6 37,7 @@ extern void xlua_pushlib_adif(lua_State
extern void xlua_pushlib_cabrillo(lua_State *L);
extern void xlua_pushlib_country(lua_State *L);
extern void xlua_pushlib_index(lua_State *L);
+extern void xlua_pushlib_iso3166(lua_State *L);
extern void xlua_pushlib_nvl(lua_State *L);
extern void xlua_pushlib_qso(lua_State *L);
extern void xlua_pushlib_sig(lua_State *L);