Skip to content

Commit 8d83d0f

Browse files
committed
Updated for Factorio 1.1.9
1 parent efe5299 commit 8d83d0f

File tree

20 files changed

+903
-71
lines changed

20 files changed

+903
-71
lines changed

src/LuaCPPUtilities.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
inline const char* lua_pushstring(lua_State* L, const std::string& s)
66
{ return lua_pushlstring(L, s.c_str(), s.size()); }
77

8+
inline const char* lua_pushstring(lua_State* L, std::string_view s)
9+
{ return lua_pushlstring(L, s.data(), s.size()); }
10+
811
inline void lua_getfield(lua_State* L, int idx, const std::string& k)
912
{ lua_getlfield(L, idx, k.c_str(), k.size()); }
1013

src/lapi.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,14 @@ LUA_API int lua_iscfunction (lua_State *L, int idx) {
290290
}
291291

292292

293-
LUA_API int lua_isnumber (lua_State *L, int idx) {
293+
LUA_API int lua_isnumberorstringconvertabletonumber (lua_State *L, int idx) {
294294
TValue n;
295295
const TValue *o = index2addr(L, idx);
296296
return tonumber(o, &n);
297297
}
298298

299299

300-
LUA_API int lua_isstring (lua_State *L, int idx) {
300+
LUA_API int lua_isstringornumberconvertabletostring (lua_State *L, int idx) {
301301
int t = lua_type(L, idx);
302302
return (t == LUA_TSTRING || t == LUA_TNUMBER);
303303
}
@@ -690,6 +690,16 @@ LUA_API void lua_getglobal (lua_State *L, const char *var) {
690690
lua_unlock(L);
691691
}
692692

693+
LUA_API void lua_rawgetglobal (lua_State *L, const char *var) {
694+
Table *reg = hvalue(&G(L)->l_registry);
695+
const TValue *gt; /* global table */
696+
lua_lock(L);
697+
checkstack_locked(L, 1);
698+
gt = luaH_getint(L, reg, LUA_RIDX_GLOBALS);
699+
setsvalue2s(L, L->top++, luaS_new(L, var));
700+
setobj2s(L, L->top - 1, luaH_get(L, hvalue(gt), L->top - 1));
701+
lua_unlock(L);
702+
}
693703

694704
LUA_API void lua_gettable (lua_State *L, int idx) {
695705
StkId t;

src/lbaselib.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static int luaB_tonumber (lua_State *L) {
8989
static int luaB_error (lua_State *L) {
9090
int level = luaL_optint(L, 2, 1);
9191
lua_settop(L, 1);
92-
if (lua_isstring(L, 1) && level > 0) { /* add extra information? */
92+
if (lua_isstringornumberconvertabletostring(L, 1) && level > 0) { /* add extra information? */
9393
luaL_where(L, level);
9494
lua_pushvalue(L, 1);
9595
lua_concat(L, 2);
@@ -300,7 +300,7 @@ static const char *generic_reader (lua_State *L, void *ud, size_t *size) {
300300
*size = 0;
301301
return NULL;
302302
}
303-
else if (!lua_isstring(L, -1))
303+
else if (!lua_isstringornumberconvertabletostring(L, -1))
304304
luaL_error(L, "reader function must return a string");
305305
lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */
306306
return lua_tolstring(L, RESERVEDSLOT, size);

src/lcorolib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static int luaB_auxwrap (lua_State *L) {
6969
lua_State *co = lua_tothread(L, lua_upvalueindex(1));
7070
int r = auxresume(L, co, lua_gettop(L));
7171
if (r < 0) {
72-
if (lua_isstring(L, -1)) { /* error object is a string? */
72+
if (lua_isstringornumberconvertabletostring(L, -1)) { /* error object is a string? */
7373
luaL_where(L, 1); /* add extra info */
7474
lua_insert(L, -2);
7575
lua_concat(L, 2);

src/ldblib.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static int db_getinfo (lua_State *L) {
117117
int arg;
118118
lua_State *L1 = getthread(L, &arg);
119119
const char *options = luaL_optstring(L, arg+2, "flnStu");
120-
if (lua_isnumber(L, arg+1)) {
120+
if (lua_isnumberorstringconvertabletonumber(L, arg+1)) {
121121
if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) {
122122
lua_pushnil(L); /* level out of range */
123123
return 1;
@@ -161,7 +161,6 @@ static int db_getinfo (lua_State *L) {
161161
return 1; /* return table */
162162
}
163163

164-
165164
static int db_getlocal (lua_State *L) {
166165
int arg;
167166
lua_State *L1 = getthread(L, &arg);
@@ -209,6 +208,8 @@ static int auxupvalue (lua_State *L, int get) {
209208
const char *name;
210209
int n = luaL_checkint(L, 2);
211210
luaL_checktype(L, 1, LUA_TFUNCTION);
211+
if (!get && lua_iscfunction(L, 1))
212+
luaL_error(L, "Cannot set upvalue of C function");
212213
name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n);
213214
if (name == NULL) return 0;
214215
lua_pushstring(L, name);

src/lgc.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,8 @@ static GCObject **sweeplist (lua_State *L, GCObject** list, GCObject **p, lu_mem
732732
int tostop; /* stop sweep when this is true */
733733
if (isgenerational(g)) { /* generational mode? */
734734
toclear = ~0; /* clear nothing */
735-
toset = bitmask(OLDBIT); /* set the old bit of all surviving objects */
736-
tostop = bitmask(OLDBIT); /* do not sweep old generation */
735+
toset = BITMASK(OLDBIT); /* set the old bit of all surviving objects */
736+
tostop = BITMASK(OLDBIT); /* do not sweep old generation */
737737
}
738738
else { /* normal mode */
739739
toclear = maskcolors; /* clear all color bits + old bit */
@@ -934,7 +934,7 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {
934934

935935

936936
#define sweepphases \
937-
(bitmask(GCSsweepstring) | bitmask(GCSsweepudata) | bitmask(GCSsweep))
937+
(BITMASK(GCSsweepstring) | BITMASK(GCSsweepudata) | BITMASK(GCSsweep))
938938

939939

940940
/*
@@ -972,7 +972,7 @@ void luaC_changemode (lua_State *L, int mode) {
972972
if (mode == g->gckind) return; /* nothing to change */
973973
if (mode == KGC_GEN) { /* change to generational mode */
974974
/* make sure gray lists are consistent */
975-
luaC_runtilstate(L, bitmask(GCSpropagate));
975+
luaC_runtilstate(L, BITMASK(GCSpropagate));
976976
g->GCestimate = gettotalbytes(g);
977977
g->gckind = KGC_GEN;
978978
}
@@ -1143,8 +1143,8 @@ static void generationalcollection (lua_State *L) {
11431143
}
11441144
else {
11451145
lu_mem estimate = g->GCestimate;
1146-
luaC_runtilstate(L, ~bitmask(GCSpause)); /* run complete cycle */
1147-
luaC_runtilstate(L, bitmask(GCSpause));
1146+
luaC_runtilstate(L, ~BITMASK(GCSpause)); /* run complete cycle */
1147+
luaC_runtilstate(L, BITMASK(GCSpause));
11481148
if (gettotalbytes(g) > (estimate / 100) * g->gcmajorinc)
11491149
g->GCestimate = 0; /* signal for a major collection */
11501150
}
@@ -1218,13 +1218,13 @@ void luaC_fullgc (lua_State *L, int isemergency) {
12181218
entersweep(L);
12191219
}
12201220
/* finish any pending sweep phase to start a new cycle */
1221-
luaC_runtilstate(L, bitmask(GCSpause));
1221+
luaC_runtilstate(L, BITMASK(GCSpause));
12221222
/* run entire collector */
1223-
luaC_runtilstate(L, ~bitmask(GCSpause));
1224-
luaC_runtilstate(L, bitmask(GCSpause));
1223+
luaC_runtilstate(L, ~BITMASK(GCSpause));
1224+
luaC_runtilstate(L, BITMASK(GCSpause));
12251225
if (origkind == KGC_GEN) { /* generational mode? */
12261226
/* generational mode must always start in propagate phase */
1227-
luaC_runtilstate(L, bitmask(GCSpropagate));
1227+
luaC_runtilstate(L, BITMASK(GCSpropagate));
12281228
}
12291229
g->gckind = origkind;
12301230
luaE_setdebt(g, stddebt(g));

src/lgc.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@
6666
#define resetbits(x,m) ((x) &= cast(lu_byte, ~(m)))
6767
#define setbits(x,m) ((x) |= (m))
6868
#define testbits(x,m) ((x) & (m))
69-
#define bitmask(b) (1<<(b))
70-
#define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2))
71-
#define l_setbit(x,b) setbits(x, bitmask(b))
72-
#define resetbit(x,b) resetbits(x, bitmask(b))
73-
#define testbit(x,b) testbits(x, bitmask(b))
69+
#define BITMASK(b) (1<<(b))
70+
#define bit2mask(b1,b2) (BITMASK(b1) | BITMASK(b2))
71+
#define l_setbit(x,b) setbits(x, BITMASK(b))
72+
#define resetbit(x,b) resetbits(x, BITMASK(b))
73+
#define testbit(x,b) testbits(x, BITMASK(b))
7474

7575

7676
/* Layout for bit use in `marked' field: */
@@ -89,7 +89,7 @@
8989
#define iswhite(x) testbits((x)->gch.marked, WHITEBITS)
9090
#define isblack(x) testbit((x)->gch.marked, BLACKBIT)
9191
#define isgray(x) /* neither white nor black */ \
92-
(!testbits((x)->gch.marked, WHITEBITS | bitmask(BLACKBIT)))
92+
(!testbits((x)->gch.marked, WHITEBITS | BITMASK(BLACKBIT)))
9393

9494
#define isold(x) testbit((x)->gch.marked, OLDBIT)
9595

0 commit comments

Comments
 (0)