Skip to content

How to print relative file path, current file name and line number in nelua #136

Answered by edubart
ghost asked this question in Q&A
Discussion options

You must be logged in to vote

This is what you wanted:

print(#[srcloc.srcname..':'..srcloc.lineno]#) -- outputs "test.nelua:1"

The srcloc variable is a preprocessor table that always have the source location for the current node being processed.

You could also create a polymorphic function that gets instantiated at every call, and print the source location where the polymorphic function was instantiated using polysrcloc:

local function f() <alwayspoly>
  print(#[polysrcloc.srcname..':'..polysrcloc.lineno]#)
end
f() -- outputs "test.nelua:5"

The polysrcloc variable is a preprocessor table that always have the source location where the current polymorphic function being processed was instantiated.

Both ways is supported…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ghost
Comment options

Answer selected by edubart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant