Browse code

app_lua: added internal alternative to luaL_openlib()

- it was deprecated in Lua API, no longer available in newer versions [wip]

Daniel-Constantin Mierla authored on 17/01/2022 07:29:13
Showing 1 changed files
... ...
@@ -184,6 +184,34 @@ int sr_lua_reload_module(unsigned int reload)
184 184
 	return 0;
185 185
 }
186 186
 
187
+/**
188
+ *
189
+ */
190
+void ksr_luaL_openlib_mode(lua_State *L, const char *libname,
191
+			     const luaL_Reg *lfuncs, int nup, int mode)
192
+{
193
+	if(mode) {
194
+		lua_getglobal(L, libname);
195
+		if (lua_isnil(L, -1)) {
196
+			lua_pop(L, 1);
197
+			lua_newtable(L);
198
+		}
199
+	} else {
200
+		lua_newtable(L);
201
+	}
202
+	luaL_setfuncs(L, lfuncs, 0);
203
+	lua_setglobal(L, libname);
204
+}
205
+
206
+/**
207
+ *
208
+ */
209
+void ksr_luaL_openlib(lua_State *L, const char *libname,
210
+			     const luaL_Reg *lfuncs, int nup)
211
+{
212
+	ksr_luaL_openlib_mode(L, libname, lfuncs, nup, 0);
213
+}
214
+
187 215
 /**
188 216
  *
189 217
  */