teal-language / tl

The compiler for Teal, a typed dialect of Lua
MIT License
2.11k stars 109 forks source link

debug.getinfo doesn't contain full source #508

Closed jadawil closed 2 years ago

jadawil commented 2 years ago

Seems like teal is breaking something in debug getinfo

Example file1.lua

return {
   get_src = function() return debug.getinfo( 2, "S" ).source end
}

file2.lua

print( file1.get_src() )

Outputs With Teal -> file2 Without Teal -> @./src/file2.lua

If file2.lua called debug.getinfo( 1, "S" ).source with teal it gets the correct full path.

Environment Teal: 0.13.2 Lua: tarantool 2.8.2

hishamhm commented 2 years ago

print( file2.get_src() )

Is there a typo in your example? I assume you mean something like:

-- file2.lua
local file1 = require("file1")
print(file1.get_src())

instead?

In any case, I couldn't reproduce it here. With your file1.lua and the file2.lua from this comment, I get:

hisham@proxy master ~/projects/tl] tl run file2.lua 
@file2.lua
hisham@proxy master ~/projects/tl] lua file2.lua      
@file2.lua
hisham@proxy master ~/projects/tl] luajit file2.lua      
@file2.lua

How exactly are you running the examples?

jadawil commented 2 years ago

Yep sorry, fixed.

The issue is when the teal loader is included so something like this:

-- main.lua  
local tl = require("tl") 
tl.loader()
local file1 = require("file1")
print( file1.get_src() )

luajit main.lua

The issue looks to be because this loader uses "loadstring" to load the files, which doesn't work well with the debug lib https://www.lua.org/pil/23.1.html

hishamhm commented 2 years ago

@jadawil Ahh, that makes sense, thank you! I'm actually using load in the loader, and I was just passing the module name as the chunkname. It's an easy change to pass it "@" .. filename instead to make it behave like the "native" loading of Lua modules by require!