diff options
| author | Mike Pall <mike> | 2012-09-24 17:33:32 +0200 |
|---|---|---|
| committer | Mike Pall <mike> | 2012-09-24 17:33:32 +0200 |
| commit | ca0bb4881f17838c9d84f0df310aa1d44da9298d (patch) | |
| tree | 6429dabaa8674839701050ab7655833675a54b0d | |
| parent | 4c7c2c831992c836cbdfd0bbad1dcc26fbd007cc (diff) | |
| download | luajit-ca0bb4881f17838c9d84f0df310aa1d44da9298d.tar.gz luajit-ca0bb4881f17838c9d84f0df310aa1d44da9298d.tar.bz2 luajit-ca0bb4881f17838c9d84f0df310aa1d44da9298d.zip | |
From Lua 5.2: Add rawlen(). Needs -DLUAJIT_ENABLE_LUA52COMPAT.
| -rw-r--r-- | src/lib_base.c | 14 | ||||
| -rw-r--r-- | src/lj_ffrecord.c | 13 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/lib_base.c b/src/lib_base.c index d63c9803..6f664eb6 100644 --- a/src/lib_base.c +++ b/src/lib_base.c | |||
| @@ -199,6 +199,20 @@ LJLIB_CF(rawequal) LJLIB_REC(.) | |||
| 199 | return 1; | 199 | return 1; |
| 200 | } | 200 | } |
| 201 | 201 | ||
| 202 | #if LJ_52 | ||
| 203 | LJLIB_CF(rawlen) LJLIB_REC(.) | ||
| 204 | { | ||
| 205 | cTValue *o = L->base; | ||
| 206 | int32_t len; | ||
| 207 | if (L->top > o && tvisstr(o)) | ||
| 208 | len = (int32_t)strV(o)->len; | ||
| 209 | else | ||
| 210 | len = (int32_t)lj_tab_len(lj_lib_checktab(L, 1)); | ||
| 211 | setintV(L->top-1, len); | ||
| 212 | return 1; | ||
| 213 | } | ||
| 214 | #endif | ||
| 215 | |||
| 202 | LJLIB_CF(unpack) | 216 | LJLIB_CF(unpack) |
| 203 | { | 217 | { |
| 204 | GCtab *t = lj_lib_checktab(L, 1); | 218 | GCtab *t = lj_lib_checktab(L, 1); |
diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c index 42bbc5f4..39c3140f 100644 --- a/src/lj_ffrecord.c +++ b/src/lj_ffrecord.c | |||
| @@ -213,6 +213,19 @@ static void LJ_FASTCALL recff_rawequal(jit_State *J, RecordFFData *rd) | |||
| 213 | } /* else: Interpreter will throw. */ | 213 | } /* else: Interpreter will throw. */ |
| 214 | } | 214 | } |
| 215 | 215 | ||
| 216 | #if LJ_52 | ||
| 217 | static void LJ_FASTCALL recff_rawlen(jit_State *J, RecordFFData *rd) | ||
| 218 | { | ||
| 219 | TRef tr = J->base[0]; | ||
| 220 | if (tref_isstr(tr)) | ||
| 221 | J->base[0] = emitir(IRTI(IR_FLOAD), tr, IRFL_STR_LEN); | ||
| 222 | else if (tref_istab(tr)) | ||
| 223 | J->base[0] = lj_ir_call(J, IRCALL_lj_tab_len, tr); | ||
| 224 | /* else: Interpreter will throw. */ | ||
| 225 | UNUSED(rd); | ||
| 226 | } | ||
| 227 | #endif | ||
| 228 | |||
| 216 | /* Determine mode of select() call. */ | 229 | /* Determine mode of select() call. */ |
| 217 | int32_t lj_ffrecord_select_mode(jit_State *J, TRef tr, TValue *tv) | 230 | int32_t lj_ffrecord_select_mode(jit_State *J, TRef tr, TValue *tv) |
| 218 | { | 231 | { |
