Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct chunkname #138

Merged
merged 2 commits into from
Oct 23, 2020
Merged

Correct chunkname #138

merged 2 commits into from
Oct 23, 2020

Conversation

actboy168
Copy link
Contributor

The chunkname specification is not part of the Lua standard, but following the specification can be more compatible with debugging and profiling tools.

The chunkname specification is included in the lua manual.

source: the source of the chunk that created the function. If source starts with a '@', it means that the function was defined in a file where the file name follows the '@'. If source starts with a '=', the remainder of its contents describes the source in a user-dependent manner. Otherwise, the function was defined in a string where source is that string.

@mikke89
Copy link
Owner

mikke89 commented Oct 21, 2020

Thanks!

The first change makes sense (adding the @). The second one however makes it harder to figure out where the script was loaded from when it gives an error, unless I am missing something?

@mikke89 mikke89 added the Lua Lua binding issues label Oct 21, 2020
@actboy168
Copy link
Contributor Author

I added the source url as a comment to the first line. In the error message, it is just a little bit different from before.

Before:

[string "luainvaders/data/game.rml"]:5: error

After:

[string "--luainvaders/data/game.rml..."]:5: error

@mikke89
Copy link
Owner

mikke89 commented Oct 22, 2020

I still don't understand the motivation for doing the second change. Do you need the debugger to print the whole code?

Instead of modifying the original code / buffer, perhaps this could be a reasonable change:

Interpreter::DoString(buffer, this->GetSourceURL() + '\n' + buffer);

@actboy168
Copy link
Contributor Author

Lua does not keep a copy of the source code in memory after compiling the source code. The debugging tool can only find the source code of this function through the chunkname of the function.

Lua's manual defines three specifications for chunkname. One starts with'@', which means that chunkname is the path of the lua source code file; the other starts with'=', which means that chunkname is a custom format, which is useful for debugging tools. In other words, it is equivalent to the source code is not visible; the third is the case outside of the above two formats, which means that chunkname is a piece of Lua source code.

So for your modification, if there is no ‘--’ at the beginning, it means that it is not a legal Lua source code. Secondly, chunkname is one line more than the real source code, which will cause the debugging tool to have a wrong offset in the positioning of the source code.

@mikke89
Copy link
Owner

mikke89 commented Oct 23, 2020

Oh, I see now, so the debugger uses the chunkname for viewing and stepping through the code. Thanks for explaining, this is just me not well versed in the Lua world.

@mikke89 mikke89 merged commit e3b74a4 into mikke89:master Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Lua Lua binding issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants