KSP-KOS / KOS

Fully programmable autopilot mod for KSP. Originally By Nivekk
Other
691 stars 229 forks source link

feature request: BOUND variables for SCRIPT FILENAME and current LINE number #2904

Open mgalyean opened 3 years ago

mgalyean commented 3 years ago

These are very handy in other scripting languages for including in prints to the debug log. When scrying through script log output it can be immensely helpful to be reminded, as one reads, which of several possible scripts and what line number was executing at the log entry point for keeping a model of the code gelled in one's mind. We can do script file name by setting a var in code for sure, but a line number bound var, like perl, ruby, and PHP's " __LINE__", or bash's "LINENO" or python's "frameinfo", or firefox javascript's "new Error().lineNumber", or ... ;)

nuggreat commented 3 years ago

There is a function to get the path of the currently executing section of code by calling SCRIPTPATH().

mgalyean commented 3 years ago

Good to know and sorry for not knowing that. My main impetus in creating this issue was making the current line number available and the script name was just an afterthought as it is typically paired with line number in log output or scripting envs where it is available and to suggest that the two are paired in a sense. Given SCRIPTPATH() and the way it appears as built-in function rather than a bound var, I'd suggest that line number be implemented with a similar appearance. Rather than a bound variable, perhaps LINENUMBER() would be more appropriate, for example. For users who have wrapper logging functions, LINENUMBER() would be yet another parameter passed; to be clear I'm not talking about dissecting the stack and figuring out what line the wrapper was called from automagically. Just a barebones function that returns the line number at which the function was called to be used as the user uses it