aboutsummaryrefslogtreecommitdiff
path: root/src/lj_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lj_lib.c')
-rw-r--r--src/lj_lib.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/lj_lib.c b/src/lj_lib.c
index 331eaa6a..b6aa97a0 100644
--- a/src/lj_lib.c
+++ b/src/lj_lib.c
@@ -18,6 +18,8 @@
18#include "lj_dispatch.h" 18#include "lj_dispatch.h"
19#include "lj_vm.h" 19#include "lj_vm.h"
20#include "lj_strscan.h" 20#include "lj_strscan.h"
21#include "lj_lex.h"
22#include "lj_bcdump.h"
21#include "lj_lib.h" 23#include "lj_lib.h"
22 24
23/* -- Library initialization ---------------------------------------------- */ 25/* -- Library initialization ---------------------------------------------- */
@@ -43,6 +45,28 @@ static GCtab *lib_create_table(lua_State *L, const char *libname, int hsize)
43 return tabV(L->top-1); 45 return tabV(L->top-1);
44} 46}
45 47
48static const uint8_t *lib_read_lfunc(lua_State *L, const uint8_t *p, GCtab *tab)
49{
50 int len = *p++;
51 GCstr *name = lj_str_new(L, (const char *)p, len);
52 LexState ls;
53 GCproto *pt;
54 GCfunc *fn;
55 memset(&ls, 0, sizeof(ls));
56 ls.L = L;
57 ls.p = (const char *)(p+len);
58 ls.pe = (const char *)~(uintptr_t)0;
59 ls.c = -1;
60 ls.level = (BCDUMP_F_STRIP|(LJ_BE*BCDUMP_F_BE));
61 ls.chunkname = name;
62 pt = lj_bcread_proto(&ls);
63 pt->firstline = ~(BCLine)0;
64 fn = lj_func_newL_empty(L, pt, tabref(L->env));
65 /* NOBARRIER: See below for common barrier. */
66 setfuncV(L, lj_tab_setstr(L, tab, name), fn);
67 return (const uint8_t *)ls.p;
68}
69
46void lj_lib_register(lua_State *L, const char *libname, 70void lj_lib_register(lua_State *L, const char *libname,
47 const uint8_t *p, const lua_CFunction *cf) 71 const uint8_t *p, const lua_CFunction *cf)
48{ 72{
@@ -87,6 +111,9 @@ void lj_lib_register(lua_State *L, const char *libname,
87 ofn = fn; 111 ofn = fn;
88 } else { 112 } else {
89 switch (tag | len) { 113 switch (tag | len) {
114 case LIBINIT_LUA:
115 p = lib_read_lfunc(L, p, tab);
116 break;
90 case LIBINIT_SET: 117 case LIBINIT_SET:
91 L->top -= 2; 118 L->top -= 2;
92 if (tvisstr(L->top+1) && strV(L->top+1)->len == 0) 119 if (tvisstr(L->top+1) && strV(L->top+1)->len == 0)