Skip to content

Commit b287f8e

Browse files
author
liyukun
committed
+ init kabletop-lua
1 parent fc6c74f commit b287f8e

74 files changed

Lines changed: 154 additions & 28166 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ testes/libs/all
1313

1414
temp
1515
lua
16+
build

all

Lines changed: 0 additions & 9 deletions
This file was deleted.

lapi.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ const char lua_ident[] =
5353
#define isupvalue(i) ((i) < LUA_REGISTRYINDEX)
5454

5555

56-
/*
57-
** Convert an acceptable index to a pointer to its respective value.
58-
** Non-valid indices return the special nil value 'G(L)->nilvalue'.
59-
*/
6056
static TValue *index2value (lua_State *L, int idx) {
6157
CallInfo *ci = L->ci;
6258
if (idx > 0) {
@@ -74,26 +70,22 @@ static TValue *index2value (lua_State *L, int idx) {
7470
else { /* upvalues */
7571
idx = LUA_REGISTRYINDEX - idx;
7672
api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large");
77-
if (ttisCclosure(s2v(ci->func))) { /* C closure? */
73+
if (ttislcf(s2v(ci->func))) /* light C function? */
74+
return &G(L)->nilvalue; /* it has no upvalues */
75+
else {
7876
CClosure *func = clCvalue(s2v(ci->func));
7977
return (idx <= func->nupvalues) ? &func->upvalue[idx-1]
8078
: &G(L)->nilvalue;
8179
}
82-
else { /* light C function or Lua function (through a hook)?) */
83-
api_check(L, ttislcf(s2v(ci->func)), "caller not a C function");
84-
return &G(L)->nilvalue; /* no upvalues */
85-
}
8680
}
8781
}
8882

89-
/*
90-
** Convert a valid actual index (not a pseudo-index) to its address.
91-
*/
83+
9284
static StkId index2stack (lua_State *L, int idx) {
9385
CallInfo *ci = L->ci;
9486
if (idx > 0) {
9587
StkId o = ci->func + idx;
96-
api_check(L, o < L->top, "invalid index");
88+
api_check(L, o < L->top, "unacceptable index");
9789
return o;
9890
}
9991
else { /* non-positive index */
@@ -1040,7 +1032,6 @@ static void f_call (lua_State *L, void *ud) {
10401032
}
10411033

10421034

1043-
10441035
LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc,
10451036
lua_KContext ctx, lua_KFunction k) {
10461037
struct CallS c;
@@ -1107,7 +1098,6 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,
11071098
return status;
11081099
}
11091100

1110-
11111101
LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip) {
11121102
int status;
11131103
TValue *o;
@@ -1122,7 +1112,6 @@ LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip) {
11221112
return status;
11231113
}
11241114

1125-
11261115
LUA_API int lua_status (lua_State *L) {
11271116
return L->status;
11281117
}

lauxlib.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "lauxlib.h"
2828

29+
#include "ltime.h"
2930

3031
#if !defined(MAX_SIZET)
3132
/* maximum value for size_t */
@@ -1083,9 +1084,14 @@ static void warnfon (void *ud, const char *message, int tocont) {
10831084
warnfcont(ud, message, tocont); /* finish processing */
10841085
}
10851086

1087+
extern long int g_time;
1088+
extern long int g_clock;
10861089

1087-
LUALIB_API lua_State *luaL_newstate (void) {
1088-
lua_State *L = lua_newstate(l_alloc, NULL);
1090+
LUALIB_API lua_State *luaL_newstate (long int _time, long int _clock) {
1091+
lua_State *L = NULL;
1092+
g_time = _time;
1093+
g_clock = _clock;
1094+
L = lua_newstate(l_alloc, NULL);
10891095
if (l_likely(L)) {
10901096
lua_atpanic(L, &panic);
10911097
lua_setwarnf(L, warnfoff, L); /* default is warnings off */

lauxlib.h

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,
9898
const char *name, const char *mode);
9999
LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
100100

101-
LUALIB_API lua_State *(luaL_newstate) (void);
101+
LUALIB_API lua_State *(luaL_newstate) (long int, long int);
102102

103103
LUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx);
104104

@@ -224,23 +224,6 @@ LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz);
224224
** File handles for IO library
225225
** =======================================================
226226
*/
227-
228-
/*
229-
** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and
230-
** initial structure 'luaL_Stream' (it may contain other fields
231-
** after that initial structure).
232-
*/
233-
234-
#define LUA_FILEHANDLE "FILE*"
235-
236-
237-
typedef struct luaL_Stream {
238-
FILE *f; /* stream (NULL for incompletely created streams) */
239-
lua_CFunction closef; /* to close stream (NULL for closed streams) */
240-
} luaL_Stream;
241-
242-
/* }====================================================== */
243-
244227
/*
245228
** {==================================================================
246229
** "Abstraction Layer" for basic report of messages and errors

lbaselib.c

Lines changed: 5 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,6 @@
2121
#include "lualib.h"
2222

2323

24-
static int luaB_print (lua_State *L) {
25-
int n = lua_gettop(L); /* number of arguments */
26-
int i;
27-
for (i = 1; i <= n; i++) { /* for each argument */
28-
size_t l;
29-
const char *s = luaL_tolstring(L, i, &l); /* convert it to string */
30-
if (i > 1) /* not the first element? */
31-
lua_writestring("\t", 1); /* add a tab before it */
32-
lua_writestring(s, l); /* print it */
33-
lua_pop(L, 1); /* pop result */
34-
}
35-
lua_writeline();
36-
return 0;
37-
}
38-
39-
4024
/*
4125
** Creates a warning with all given arguments.
4226
** Check first for errors; otherwise an error may interrupt
@@ -261,11 +245,6 @@ static int luaB_next (lua_State *L) {
261245
}
262246

263247

264-
static int pairscont (lua_State *L, int status, lua_KContext k) {
265-
(void)L; (void)status; (void)k; /* unused */
266-
return 3;
267-
}
268-
269248
static int luaB_pairs (lua_State *L) {
270249
luaL_checkany(L, 1);
271250
if (luaL_getmetafield(L, 1, "__pairs") == LUA_TNIL) { /* no metamethod? */
@@ -275,7 +254,7 @@ static int luaB_pairs (lua_State *L) {
275254
}
276255
else {
277256
lua_pushvalue(L, 1); /* argument 'self' to metamethod */
278-
lua_callk(L, 1, 3, 0, pairscont); /* get 3 values from metamethod */
257+
lua_call(L, 1, 3); /* get 3 values from metamethod */
279258
}
280259
return 3;
281260
}
@@ -304,32 +283,6 @@ static int luaB_ipairs (lua_State *L) {
304283
}
305284

306285

307-
static int load_aux (lua_State *L, int status, int envidx) {
308-
if (l_likely(status == LUA_OK)) {
309-
if (envidx != 0) { /* 'env' parameter? */
310-
lua_pushvalue(L, envidx); /* environment for loaded function */
311-
if (!lua_setupvalue(L, -2, 1)) /* set it as 1st upvalue */
312-
lua_pop(L, 1); /* remove 'env' if not used by previous call */
313-
}
314-
return 1;
315-
}
316-
else { /* error (message is on top of the stack) */
317-
luaL_pushfail(L);
318-
lua_insert(L, -2); /* put before error message */
319-
return 2; /* return fail plus error message */
320-
}
321-
}
322-
323-
324-
static int luaB_loadfile (lua_State *L) {
325-
const char *fname = luaL_optstring(L, 1, NULL);
326-
const char *mode = luaL_optstring(L, 2, NULL);
327-
int env = (!lua_isnone(L, 3) ? 3 : 0); /* 'env' index or 0 if no 'env' */
328-
int status = luaL_loadfilex(L, fname, mode);
329-
return load_aux(L, status, env);
330-
}
331-
332-
333286
/*
334287
** {======================================================
335288
** Generic Read function
@@ -345,67 +298,9 @@ static int luaB_loadfile (lua_State *L) {
345298
#define RESERVEDSLOT 5
346299

347300

348-
/*
349-
** Reader for generic 'load' function: 'lua_load' uses the
350-
** stack for internal stuff, so the reader cannot change the
351-
** stack top. Instead, it keeps its resulting string in a
352-
** reserved slot inside the stack.
353-
*/
354-
static const char *generic_reader (lua_State *L, void *ud, size_t *size) {
355-
(void)(ud); /* not used */
356-
luaL_checkstack(L, 2, "too many nested functions");
357-
lua_pushvalue(L, 1); /* get function */
358-
lua_call(L, 0, 1); /* call it */
359-
if (lua_isnil(L, -1)) {
360-
lua_pop(L, 1); /* pop result */
361-
*size = 0;
362-
return NULL;
363-
}
364-
else if (l_unlikely(!lua_isstring(L, -1)))
365-
luaL_error(L, "reader function must return a string");
366-
lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */
367-
return lua_tolstring(L, RESERVEDSLOT, size);
368-
}
369-
370-
371-
static int luaB_load (lua_State *L) {
372-
int status;
373-
size_t l;
374-
const char *s = lua_tolstring(L, 1, &l);
375-
const char *mode = luaL_optstring(L, 3, "bt");
376-
int env = (!lua_isnone(L, 4) ? 4 : 0); /* 'env' index or 0 if no 'env' */
377-
if (s != NULL) { /* loading a string? */
378-
const char *chunkname = luaL_optstring(L, 2, s);
379-
status = luaL_loadbufferx(L, s, l, chunkname, mode);
380-
}
381-
else { /* loading from a reader function */
382-
const char *chunkname = luaL_optstring(L, 2, "=(load)");
383-
luaL_checktype(L, 1, LUA_TFUNCTION);
384-
lua_settop(L, RESERVEDSLOT); /* create reserved slot */
385-
status = lua_load(L, generic_reader, NULL, chunkname, mode);
386-
}
387-
return load_aux(L, status, env);
388-
}
389-
390301
/* }====================================================== */
391302

392303

393-
static int dofilecont (lua_State *L, int d1, lua_KContext d2) {
394-
(void)d1; (void)d2; /* only to match 'lua_Kfunction' prototype */
395-
return lua_gettop(L) - 1;
396-
}
397-
398-
399-
static int luaB_dofile (lua_State *L) {
400-
const char *fname = luaL_optstring(L, 1, NULL);
401-
lua_settop(L, 1);
402-
if (l_unlikely(luaL_loadfile(L, fname) != LUA_OK))
403-
return lua_error(L);
404-
lua_callk(L, 0, LUA_MULTRET, 0, dofilecont);
405-
return dofilecont(L, 0, 0);
406-
}
407-
408-
409304
static int luaB_assert (lua_State *L) {
410305
if (l_likely(lua_toboolean(L, 1))) /* condition is true? */
411306
return lua_gettop(L); /* return all arguments */
@@ -490,16 +385,16 @@ static int luaB_tostring (lua_State *L) {
490385
static const luaL_Reg base_funcs[] = {
491386
{"assert", luaB_assert},
492387
{"collectgarbage", luaB_collectgarbage},
493-
{"dofile", luaB_dofile},
388+
/* {"dofile", luaB_dofile}, */
494389
{"error", luaB_error},
495390
{"getmetatable", luaB_getmetatable},
496391
{"ipairs", luaB_ipairs},
497-
{"loadfile", luaB_loadfile},
498-
{"load", luaB_load},
392+
/* {"loadfile", luaB_loadfile}, */
393+
/* {"load", luaB_load}, */
499394
{"next", luaB_next},
500395
{"pairs", luaB_pairs},
501396
{"pcall", luaB_pcall},
502-
{"print", luaB_print},
397+
/* {"print", luaB_print}, */
503398
{"warn", luaB_warn},
504399
{"rawequal", luaB_rawequal},
505400
{"rawlen", luaB_rawlen},

lcode.c

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "lprefix.h"
1111

1212

13-
#include <float.h>
1413
#include <limits.h>
1514
#include <math.h>
1615
#include <stdlib.h>
@@ -581,41 +580,24 @@ static int stringK (FuncState *fs, TString *s) {
581580

582581
/*
583582
** Add an integer to list of constants and return its index.
583+
** Integers use userdata as keys to avoid collision with floats with
584+
** same value; conversion to 'void*' is used only for hashing, so there
585+
** are no "precision" problems.
584586
*/
585587
static int luaK_intK (FuncState *fs, lua_Integer n) {
586-
TValue o;
588+
TValue k, o;
589+
setpvalue(&k, cast_voidp(cast_sizet(n)));
587590
setivalue(&o, n);
588-
return addk(fs, &o, &o); /* use integer itself as key */
591+
return addk(fs, &k, &o);
589592
}
590593

591594
/*
592-
** Add a float to list of constants and return its index. Floats
593-
** with integral values need a different key, to avoid collision
594-
** with actual integers. To that, we add to the number its smaller
595-
** power-of-two fraction that is still significant in its scale.
596-
** For doubles, that would be 1/2^52.
597-
** (This method is not bulletproof: there may be another float
598-
** with that value, and for floats larger than 2^53 the result is
599-
** still an integer. At worst, this only wastes an entry with
600-
** a duplicate.)
595+
** Add a float to list of constants and return its index.
601596
*/
602597
static int luaK_numberK (FuncState *fs, lua_Number r) {
603598
TValue o;
604-
lua_Integer ik;
605599
setfltvalue(&o, r);
606-
if (!luaV_flttointeger(r, &ik, F2Ieq)) /* not an integral value? */
607-
return addk(fs, &o, &o); /* use number itself as key */
608-
else { /* must build an alternative key */
609-
const int nbm = l_floatatt(MANT_DIG);
610-
const lua_Number q = l_mathop(ldexp)(1.0, -nbm + 1);
611-
const lua_Number k = (ik == 0) ? q : r + r*q; /* new key */
612-
TValue kv;
613-
setfltvalue(&kv, k);
614-
/* result is not an integral value, unless value is too large */
615-
lua_assert(!luaV_flttointeger(k, &ik, F2Ieq) ||
616-
l_mathop(fabs)(r) >= l_mathop(1e6));
617-
return addk(fs, &kv, &o);
618-
}
600+
return addk(fs, &o, &o); /* use number itself as key */
619601
}
620602

621603

0 commit comments

Comments
 (0)