@@ -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 }
0 commit comments