Skip to content

Commit 1299fcd

Browse files
committed
Updated for Factorio 2.0.46
1 parent ce12474 commit 1299fcd

30 files changed

+592
-135
lines changed

src/LuaCPPUtilities.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ inline void lua_getfield(lua_State* L, int idx, const std::string& k)
1414
inline void lua_setfield(lua_State* L, int idx, const std::string& k)
1515
{ lua_setlfield(L, idx, k.c_str(), k.size()); }
1616

17-
template<class T>
18-
inline std::enable_if_t<!std::is_same_v<T, lua_Number>> lua_pushnumber(lua_State* L, T value)
17+
template<class T> requires (!std::is_same_v<T, lua_Number>)
18+
inline void lua_pushnumber(lua_State* L, T value)
1919
{ lua_pushnumber(L, lua_Number(value)); }

src/lapi.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const char lua_ident[] =
3636

3737

3838
/* value at a non-valid index */
39-
#define NONVALIDVALUE cast(TValue *, luaO_nilobject)
39+
#define NONVALIDVALUE lua_cast(TValue *, luaO_nilobject)
4040

4141
/* corresponding test */
4242
#define isvalid(o) ((o) != luaO_nilobject)
@@ -333,7 +333,7 @@ LUA_API void lua_arith (lua_State *L, int op) {
333333
changenvalue(o1, luaO_arith(op, nvalue(o1), nvalue(o2)));
334334
}
335335
else
336-
luaV_arith(L, o1, o1, o2, cast(TMS, op - LUA_OPADD + TM_ADD));
336+
luaV_arith(L, o1, o1, o2, lua_cast(TMS, op - LUA_OPADD + TM_ADD));
337337
L->top--;
338338
lua_unlock(L);
339339
}
@@ -500,16 +500,17 @@ LUA_API lua_State *lua_tothread (lua_State *L, int idx) {
500500

501501
LUA_API const void *lua_topointer (lua_State *L, int idx) {
502502
StkId o = index2addr(L, idx);
503-
switch (ttypenv(o)) {
503+
switch (ttype(o)) {
504504
case LUA_TTABLE: return hvalue(o);
505505
case LUA_TLCL: return clLvalue(o);
506506
case LUA_TCCL: return clCvalue(o);
507-
case LUA_TLCF: return cast(void *, cast(size_t, fvalue(o)));
507+
case LUA_TLCF: return lua_cast(void *, lua_cast(size_t, fvalue(o)));
508508
case LUA_TTHREAD: return thvalue(o);
509509
case LUA_TUSERDATA:
510510
case LUA_TLIGHTUSERDATA:
511511
return lua_touserdata(L, idx);
512-
case LUA_TSTRING:
512+
case LUA_TSHRSTR:
513+
case LUA_TLNGSTR:
513514
return svalue(o);
514515
default: return NULL;
515516
}
@@ -759,7 +760,7 @@ LUA_API void lua_rawgetp (lua_State *L, int idx, const void *p) {
759760
checkstack_locked(L, 1);
760761
t = index2addr(L, idx);
761762
api_check(L, ttistable(t), "table expected");
762-
setpvalue(&k, cast(void *, p));
763+
setpvalue(&k, lua_cast(void *, p));
763764
setobj2s(L, L->top, luaH_get(L, hvalue(t), &k));
764765
api_incr_top(L);
765766
lua_unlock(L);
@@ -943,7 +944,7 @@ LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) {
943944
api_checknelems(L, 1);
944945
t = index2addr(L, idx);
945946
api_check(L, ttistable(t), "table expected");
946-
setpvalue(&k, cast(void *, p));
947+
setpvalue(&k, lua_cast(void *, p));
947948
setobj2t(L, luaH_set(L, hvalue(t), &k), L->top - 1);
948949
luaC_barrierback(L, gcvalue(t), L->top - 1);
949950
L->top--;
@@ -1063,7 +1064,7 @@ struct CallS { /* data to `f_call' */
10631064

10641065

10651066
static void f_call (lua_State *L, void *ud) {
1066-
struct CallS *c = cast(struct CallS *, ud);
1067+
struct CallS *c = lua_cast(struct CallS *, ud);
10671068
luaD_call(L, c->func, c->nresults, 0);
10681069
}
10691070

@@ -1202,7 +1203,7 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
12021203
luaC_forcestep(L); /* do a single step */
12031204
}
12041205
else {
1205-
lu_mem debt = cast(lu_mem, data) * 1024 - GCSTEPSIZE;
1206+
lu_mem debt = lua_cast(lu_mem, data) * 1024 - GCSTEPSIZE;
12061207
if (g->gcrunning)
12071208
debt += g->GCdebt; /* include current debt */
12081209
luaE_setdebt(g, debt);

src/lauxlib.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,17 @@ static int countlevels (lua_State *L) {
114114

115115

116116
LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1,
117-
const char *msg, int level) {
117+
const char *msg, int level, const struct CallInfo* stopat) {
118118
lua_Debug ar;
119119
int top = lua_gettop(L);
120120
int numlevels = countlevels(L1);
121-
int mark = (numlevels > LEVELS1 + LEVELS2) ? LEVELS1 : 0;
121+
int mark = (numlevels > LEVELS1 + LEVELS2 && !stopat) ? LEVELS1 : 0;
122122
if (msg) lua_pushfstring(L, "%s\n", msg);
123123
lua_pushliteral(L, "stack traceback:");
124124
while (lua_getstack(L1, level++, &ar)) {
125-
if (level == mark) { /* too many levels? */
125+
if (ar.i_ci == stopat) {
126+
break;
127+
} else if (level == mark) { /* too many levels? */
126128
lua_pushliteral(L, "\n\t..."); /* add a '...' */
127129
level = numlevels - LEVELS2; /* and skip to last ones */
128130
}
@@ -153,7 +155,7 @@ LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1,
153155
LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) {
154156
lua_Debug ar;
155157
if (!lua_getstack(L, 0, &ar)) /* no stack frame? */
156-
return luaL_error(L, "bad argument #%d of %d (%s)", narg < 0 ? narg + lua_gettop(L) + 1 : narg, lua_gettop(L), extramsg);
158+
return luaL_error(L, "bad argument #%d of %d (%s)", lua_absindex(L, narg), lua_gettop(L), extramsg);
157159
lua_getinfo(L, "n", &ar);
158160
if (strcmp(ar.namewhat, "method") == 0) {
159161
narg--; /* do not count `self' */
@@ -162,10 +164,18 @@ LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) {
162164
}
163165
if (ar.name == NULL)
164166
ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : "?";
165-
return luaL_error(L, "bad argument #%d of %d to " LUA_QS " (%s)",
166-
narg < 0 ? narg + lua_gettop(L) + 1 : narg, lua_gettop(L), ar.name, extramsg);
167+
return luaL_error(L, "bad argument #%d of %d to " LUA_QS " (%s)", lua_absindex(L, narg), lua_gettop(L), ar.name, extramsg);
167168
}
168169

170+
LUALIB_API int luaL_argcounterror(lua_State *L, const char *msg) {
171+
lua_Debug ar;
172+
if (!lua_getstack(L, 0, &ar)) /* no stack frame? */
173+
return luaL_error(L, "Arguments count error: %s", msg);
174+
lua_getinfo(L, "n", &ar);
175+
if (ar.name == NULL)
176+
ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : "?";
177+
return luaL_error(L, "Arguments count error for " LUA_QS ": %s", ar.name, msg);
178+
}
169179

170180
static int typeerror (lua_State *L, int narg, const char *tname) {
171181
const char *msg = lua_pushfstring(L, "%s expected, got %s",

src/lauxlib.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
3333
LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
3434
LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len);
3535
LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg);
36+
LUALIB_API int (luaL_argcounterror) (lua_State *L, const char *msg);
3637
LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg,
3738
size_t *l);
3839
LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg,
@@ -93,7 +94,7 @@ LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);
9394
LUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname);
9495

9596
LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1,
96-
const char *msg, int level);
97+
const char *msg, int level, const struct CallInfo* stopat);
9798

9899
LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
99100
lua_CFunction openf, int glb);

src/lbaselib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static int luaB_setmetatable (lua_State *L) {
114114
luaL_checktype(L, 1, LUA_TTABLE);
115115
if (t != LUA_TNIL && t != LUA_TTABLE)
116116
{
117-
const char* msg = lua_pushfstring(L, "nil or table expected got %s", lua_typename(L, 2));
117+
const char* msg = lua_pushfstring(L, "nil or table expected got %s", lua_typename(L, lua_type(L, 2)));
118118
luaL_argerror(L, 2, msg);
119119
}
120120
if (luaL_getmetafield(L, 1, "__metatable"))

src/lcode.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -844,15 +844,15 @@ void luaK_posfix (FuncState *fs, BinOpr op,
844844
}
845845
case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
846846
case OPR_MOD: case OPR_POW: {
847-
codearith(fs, cast(OpCode, op - OPR_ADD + OP_ADD), e1, e2, line);
847+
codearith(fs, lua_cast(OpCode, op - OPR_ADD + OP_ADD), e1, e2, line);
848848
break;
849849
}
850850
case OPR_EQ: case OPR_LT: case OPR_LE: {
851-
codecomp(fs, cast(OpCode, op - OPR_EQ + OP_EQ), 1, e1, e2);
851+
codecomp(fs, lua_cast(OpCode, op - OPR_EQ + OP_EQ), 1, e1, e2);
852852
break;
853853
}
854854
case OPR_NE: case OPR_GT: case OPR_GE: {
855-
codecomp(fs, cast(OpCode, op - OPR_NE + OP_EQ), 0, e1, e2);
855+
codecomp(fs, lua_cast(OpCode, op - OPR_NE + OP_EQ), 0, e1, e2);
856856
break;
857857
}
858858
default: lua_assert(0);

src/ldblib.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static int db_setmetatable (lua_State *L) {
4141
int t = lua_type(L, 2);
4242
if (t != LUA_TNIL && t != LUA_TTABLE)
4343
{
44-
const char* msg = lua_pushfstring(L, "nil or table expected got %s", lua_typename(L, 2));
44+
const char* msg = lua_pushfstring(L, "nil or table expected got %s", lua_typename(L, lua_type(L, 2)));
4545
luaL_argerror(L, 2, msg);
4646
}
4747
lua_settop(L, 2);
@@ -370,7 +370,7 @@ static int db_traceback (lua_State *L) {
370370
lua_pushvalue(L, arg + 1); /* return it untouched */
371371
else {
372372
int level = luaL_optint(L, arg + 2, (L == L1) ? 1 : 0);
373-
luaL_traceback(L, L1, msg, level);
373+
luaL_traceback(L, L1, msg, level, NULL);
374374
}
375375
return 1;
376376
}

src/ldebug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "lstate.h"
1212

1313

14-
#define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1)
14+
#define pcRel(pc, p) (lua_cast(int, (pc) - (p)->code) - 1)
1515

1616
#define getfuncline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0)
1717

src/ldo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ static l_noret resume_error (lua_State *L, const char *msg, StkId firstArg) {
517517
*/
518518
static void resume (lua_State *L, void *ud) {
519519
int nCcalls = L->nCcalls;
520-
StkId firstArg = cast(StkId, ud);
520+
StkId firstArg = lua_cast(StkId, ud);
521521
CallInfo *ci = L->ci;
522522
if (nCcalls >= LUAI_MAXCCALLS)
523523
resume_error(L, "C stack overflow", firstArg);
@@ -662,7 +662,7 @@ static void checkmode (lua_State *L, const char *mode, const char *x) {
662662
static void f_parser (lua_State *L, void *ud) {
663663
int i;
664664
Closure *cl;
665-
struct SParser *p = cast(struct SParser *, ud);
665+
struct SParser *p = lua_cast(struct SParser *, ud);
666666
int c = zgetc(p->z); /* read first character */
667667
if (c == LUA_SIGNATURE[0]) {
668668
checkmode(L, p->mode, "binary");

src/lfunc.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
#include "lobject.h"
1212

1313

14-
#define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \
15-
cast(int, sizeof(TValue)*((n)-1)))
14+
#define sizeCclosure(n) (lua_cast(int, sizeof(CClosure)) + \
15+
lua_cast(int, sizeof(TValue)*((n)-1)))
1616

17-
#define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \
18-
cast(int, sizeof(TValue *)*((n)-1)))
17+
#define sizeLclosure(n) (lua_cast(int, sizeof(LClosure)) + \
18+
lua_cast(int, sizeof(TValue *)*((n)-1)))
1919

2020

2121
LUAI_FUNC Proto *luaF_newproto (lua_State *L);

0 commit comments

Comments
 (0)