MRI: rewrite script eval (was: Question about $0) #24

Merged
cremno merged 7 commits from mri-rewrite-script-eval into master 2014-04-12 09:54:13 +00:00
cremno commented 2014-04-10 13:16:45 +00:00 (Migrated from github.com)

Maybe there is a reason for setting $0. Could you tell me? I can only speculate:

It's far easier and more intuitive than this which doesn't work with mkxp:

$RGSS_SCRIPTS[__FILE__[/Section(\d+)/, 1].to_i][0]  # RGSS1 (and 2?)

So if that's a mkxp-specific extension, then it should be mentioned in the README.

Maybe there is a reason for setting `$0`. Could you tell me? I can only speculate: It's far easier and more intuitive than this which doesn't work with mkxp: ``` ruby $RGSS_SCRIPTS[__FILE__[/Section(\d+)/, 1].to_i][0] # RGSS1 (and 2?) ``` So if that's a mkxp-specific extension, then it should be mentioned in the README.
cremno commented 2014-04-09 21:52:50 +00:00 (Migrated from github.com)
Relevant code line: https://github.com/Ancurio/mkxp/blob/f06769b434/binding-mri/binding-mri.cpp#L269
Ancurio commented 2014-04-09 22:22:35 +00:00 (Migrated from github.com)

The reason as far as I remember was me desperately trying to get ruby to output script names inside exception backtraces. Alas, I failed; I don't think there's a need to call this function.

This is one part that really frustrated me too because I was able to almost perfectly replicate exception messages in the mruby binding ^^"

The reason as far as I remember was me desperately trying to get ruby to output script names inside exception backtraces. Alas, I failed; I don't think there's a need to call this function. This is one part that really frustrated me too because I was able to almost perfectly replicate exception messages in the mruby binding ^^"
cremno commented 2014-04-10 13:33:08 +00:00 (Migrated from github.com)

I closed #23. I wanted to send two separate PRs, but I think $RGSS_SCRIPTS, $0 and __FILE__ are related enough. The code above should work now!

As I've already said I'm trying to get the Hermes 0.4 demo (among other things) to run under mkxp and now it's (hopefully) only Ruby 1.9+ issues I have to deal with. Other scripts that are using those things aren't important (to me). They're mainly used for debugging or better error printing which might be helpful when porting games.

I also don't know why the RGSS isn't setting __FILE__ to the script's name. That can be done and would fix useless filenames in warnings and error messages. At least in the last case that can be fixed, but even that is kinda messy.

I closed #23. I wanted to send two separate PRs, but I think `$RGSS_SCRIPTS`, `$0` and `__FILE__` are related enough. The code above should work now! As I've already said I'm trying to get the Hermes 0.4 demo (among other things) to run under mkxp and now it's (hopefully) only Ruby 1.9+ issues I have to deal with. Other scripts that are using those things aren't important (to me). They're mainly used for debugging or better error printing which might be helpful when porting games. I also don't know why the RGSS isn't setting `__FILE__` to the script's name. That can be done and would fix useless filenames in warnings and error messages. At least in the last case that can be fixed, but even that is kinda messy.
Ancurio commented 2014-04-11 10:50:25 +00:00 (Migrated from github.com)

I also don't know why the RGSS isn't setting FILE to the script's name. That can be done and would fix useless filenames in warnings and error messages. At least in the last case that can be fixed, but even that is kinda messy.

Yeah, that seems pretty backward. It would be nice to add a config bool sometime later to override this behavior and set FILE to the actual script name, for debugging purposes.

I really really like that you found a way to force the script encoding into UTF8 without using the ugly header solution; that was seriously giving me headaches when I had to implement it! (It also screwed up the line numbers in backtraces)

> I also don't know why the RGSS isn't setting **FILE** to the script's name. That can be done and would fix useless filenames in warnings and error messages. At least in the last case that can be fixed, but even that is kinda messy. Yeah, that seems pretty backward. It would be nice to add a config bool sometime later to override this behavior and set **FILE** to the actual script name, for debugging purposes. I really really like that you found a way to force the script encoding into UTF8 without using the ugly header solution; that was seriously giving me headaches when I had to implement it! (It also screwed up the line numbers in backtraces)
Ancurio commented 2014-04-11 12:41:56 +00:00 (Migrated from github.com)

Alright, this looks good so far. I'll test it a bit more when I get time and then do the merge.

Alright, this looks good so far. I'll test it a bit more when I get time and then do the merge.
cremno commented 2014-04-11 16:27:57 +00:00 (Migrated from github.com)

Yeah, that seems pretty backward. It would be nice to add a config bool sometime later to override this behavior and set FILE to the actual script name, for debugging purposes.

Added! Feel free to change the name or default setting. I'm not good at naming things and the default (Section042) isn't helpful at the moment. I may look into better backtraces in the future, but this will definitely be another PR.

> Yeah, that seems pretty backward. It would be nice to add a config bool sometime later to override this behavior and set FILE to the actual script name, for debugging purposes. Added! Feel free to change the name or default setting. I'm not good at naming things and the default (`Section042`) isn't helpful at the moment. I may look into better backtraces in the future, but this will definitely be another PR.
Ancurio commented 2014-04-12 09:53:07 +00:00 (Migrated from github.com)

Hey, that's awesome! I just tried this with a game I've been debugging a week ago, and the new backtraces make things a million times easier to trace down. Also, warnings during runtime finally have proper locations attached to them which makes them a lot less cryptic. All in all this is a big win.

As always, thanks a lot for your contribution!

Hey, that's awesome! I just tried this with a game I've been debugging a week ago, and the new backtraces make things a million times easier to trace down. Also, warnings during runtime finally have proper locations attached to them which makes them a lot less cryptic. All in all this is a big win. As always, thanks a lot for your contribution!
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: MapleShrine/mkxp#24
No description provided.