summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/lauxlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lua/lauxlib.c')
-rw-r--r--apps/plugins/lua/lauxlib.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/apps/plugins/lua/lauxlib.c b/apps/plugins/lua/lauxlib.c
index 9597f63c60..5e7c15931d 100644
--- a/apps/plugins/lua/lauxlib.c
+++ b/apps/plugins/lua/lauxlib.c
@@ -11,10 +11,12 @@
11#include <stdio.h> 11#include <stdio.h>
12#include <stdlib.h> 12#include <stdlib.h>
13#include <string.h> 13#include <string.h>
14#include "lstring.h" /* ROCKLUA ADDED */
14 15
15 16
16/* This file uses only the official API of Lua. 17/* This file uses only the official API of Lua.
17** Any function declared here could be written as an application function. 18** Any function declared here could be written as an application function.
19** Note ** luaS_newlloc breaks this guarantee ROCKLUA ADDED
18*/ 20*/
19 21
20#define lauxlib_c 22#define lauxlib_c
@@ -239,23 +241,36 @@ LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) {
239} 241}
240 242
241 243
244 /* ROCKLUA ADDED */
245static int libsize_storenames (lua_State *L, const char* libname, const luaL_Reg *l) {
246 int size = 0;
247 if (libname)
248 luaS_newlloc(L, libname, TSTR_INBIN);
249 for (; l->name; l++) {
250 size++;
251 luaS_newlloc(L, l->name, TSTR_INBIN);
252 }
253 return size;
254}
255
256
242LUALIB_API void (luaL_register) (lua_State *L, const char *libname, 257LUALIB_API void (luaL_register) (lua_State *L, const char *libname,
243 const luaL_Reg *l) { 258 const luaL_Reg *l) {
244 luaI_openlib(L, libname, l, 0); 259 luaI_openlib(L, libname, l, 0);
245} 260}
246 261
247 262#if 0
248static int libsize (const luaL_Reg *l) { 263static int libsize (const luaL_Reg *l) {
249 int size = 0; 264 int size = 0;
250 for (; l->name; l++) size++; 265 for (; l->name; l++) size++;
251 return size; 266 return size;
252} 267}
253 268#endif
254 269
255LUALIB_API void luaI_openlib (lua_State *L, const char *libname, 270LUALIB_API void luaI_openlib (lua_State *L, const char *libname,
256 const luaL_Reg *l, int nup) { 271 const luaL_Reg *l, int nup) {
272 int size = libsize_storenames(L, libname, l);
257 if (libname) { 273 if (libname) {
258 int size = libsize(l);
259 /* check whether lib already exists */ 274 /* check whether lib already exists */
260 luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); 275 luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1);
261 lua_getfield(L, -1, libname); /* get _LOADED[libname] */ 276 lua_getfield(L, -1, libname); /* get _LOADED[libname] */