Skip to content

Commit 688db7d

Browse files
authored
Add simplified support for debug.getinfo() (#524)
Adds a simplified debug.getinfo() function to yafc-ce lua. It only returns "short_src", the part used by mods that needs this function. Tested with mod from #455, and whole py suite.
2 parents fcb32ce + 2b58f05 commit 688db7d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Yafc.Parser/LuaContext.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,15 @@ private enum Type {
141141
private readonly Dictionary<(string mod, string name), byte[]> modFixes = [];
142142

143143
private static readonly ILogger logger = Logging.GetLogger<LuaContext>();
144-
144+
private string currentfile;
145145
public LuaContext() {
146146
L = luaL_newstate();
147147
_ = luaL_openlibs(L);
148148
RegisterApi(Log, "raw_log");
149149
RegisterApi(Require, "require");
150150
RegisterApi(DebugTraceback, "debug", "traceback");
151+
RegisterApi(DebugGetinfo, "debug", "getinfo");
152+
currentfile = "__no__/file";
151153
_ = lua_pushstring(L, Project.currentYafcVersion.ToString());
152154
lua_setglobal(L, "yafc_version");
153155
var mods = NewTable();
@@ -232,6 +234,13 @@ private int DebugTraceback(IntPtr lua) {
232234
return 1;
233235
}
234236

237+
private int DebugGetinfo(IntPtr lua) {
238+
LuaTable outdata = NewTable();
239+
outdata["short_src"] = currentfile;
240+
PushManagedObject(outdata);
241+
return 1;
242+
}
243+
235244
private int Log(IntPtr lua) {
236245
logger.Information(GetString(1));
237246
return 0;
@@ -463,6 +472,7 @@ private int Require(IntPtr lua) {
463472
}
464473

465474
logger.Information("Require {RequiredFile}", requiredFile.mod + "/" + requiredFile.path);
475+
currentfile = "__" + requiredFile.mod + "__/" + requiredFile.path;
466476
byte[] bytes = FactorioDataSource.ReadModFile(requiredFile.mod, requiredFile.path);
467477

468478
if (bytes != null) {
@@ -569,6 +579,7 @@ public void DoModFiles(string[] modorder, string fileName, IProgress<(string, st
569579
}
570580

571581
logger.Information("Executing file {Filename}", mod + "/" + fileName);
582+
currentfile = "__" + mod + "__/" + fileName;
572583
_ = Exec(bytes, mod, fileName);
573584
RunModFix(mod, fileName);
574585
}

changelog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
// Internal changes:
1919
// Changes to the code that do not affect the behavior of the program.
2020

21+
----------------------------------------------------------------------------------------------------------------------
22+
Version:
23+
Date:
24+
Fixes:
25+
- Add simplified support for debug.getinfo(), only returns short_src. Fixes #455, #504.
2126
----------------------------------------------------------------------------------------------------------------------
2227
Version: 2.15.0
2328
Date: September 1st 2025

0 commit comments

Comments
 (0)