One option is to use an older daily build or the last release build until you have time to adapt to this change.
Just out of curiosity, why are you overwriting system globals? What is the use case? Which ones are you overwriting?
Rob
One option is to use an older daily build or the last release build until you have time to adapt to this change.
Just out of curiosity, why are you overwriting system globals? What is the use case? Which ones are you overwriting?
Rob
Rob, it suits me to use it in the way I’m using it. I’ll live with the perceived ‘bad practice’.
I don’t really want to ‘adjust to the change’, because what that entails is me having to alter 10,000 or more lines of code.
FYI, I’m overwriting print in this particular instance, and up until now, it worked absolutely perfectly.
That’s not to say I don’t override other system functions to do my bidding. Actually, it’s one of the strengths of lua as far as I’m concerned, and you just took that away from us
I know what your reply is going to be… so let me just preempt that by saying that I really don’t want to “think about it a little more carefully and make your override local to your project code”. That’s fine when you’re starting a blank project, but this is a mature business app we’ve been developing in Corona for a number of years, and you guys just broke it.
Unless you want to supply a few guys for a few hundred man hours to come and refactor our code to suit coding practices you insist we adopt?..
We haven’t taken anything away, we’ve just made it much harder to shoot yourself in the foot (which was a recurring issue). As the original article says:
… but if you’re deep in the heart of Lua and are accessing the _G globals table, you can still do so via Runtime._G, but this is advanced usage and the safety net comes off. And, if you really, truly need to change the value of a system global, you can always use Lua’s rawset() (but if you really need to do it, you’d know this already).
If it isn’t clear from this how to globally override print() then feel free to send me a PM with your current code and I’ll translate it for you.
Not exactly sure what you’d like to see of my current code? All half a million lines of code over 22 modules? Because that’s what I’m asking for; I’d like that my overwritten Print function worked seamlessly across all of that in tomorrows Corona the way it worked yesterday without you arbitrarily deciding to break 4 years worth of development because you suddenly figured you’d introduce some mandatory coding standards.
So yeah, I don’t really see how my giving you code would make any difference. Make what worked before work again please.
Even if I have to put a switch at the top of my main.lua saying iUnderstandImABadBadCoderAndReallyShouldntDoItLikeThis(“true”)
(obviously I tried using Runtime._G.Print, but it DOES NOT work the same as it did before)
I have a require(“utilities”) that takes care of overwrites like print. I just had to prepend Runtime._G.nameoffunction
here’s an snippet of what I have.
--- Overwrites the print function and adds a check to see if it is a table, then output it like print\_r -- @param ... -- @usage print(variableName) -- @see print\_r function Runtime.\_G.print(...) --Cycle through each argument for i=1, #arg do if(arg[i]) then --If a table, output it like print\_r if(type(arg[i]) == "table" or type(arg[i]) == "function") then Runtime.\_G.print\_r(arg[i]) else \_oldPrint(arg[i]) end end end end
But immediately calling print() afterwards does not work… If you aren’t using composer and going to print() in the main.lua before the first scene transition, you’ll need to put some sort of short delay to output it. I’m sure someone else has a better way to do it, but i don’t print anything inside the main.lua, but in the composer scenes afterwards.
Edit: user error on my part (see next 2 posts)
@JWiow I sent you a PM. We can resolve this to your satisfaction.
@noriega I’m not completely sure what you mean by “immediately calling print() afterwards does not work” …
I created utilities.lua and put your code above in it (I removed the Runtime._G. from the print_r() call as that doesn’t make sense; print_r() is presumably defined in your utilities.lua file, it’s not a system global).
I added this to my main.lua and got exactly what I should:
local utilities = require('utilities') local myTable = { one = 1, two = 2, three = 3 } print(myTable)
What am I doing differently?
+1 This is actually a *feature* of the language – regardless that beginners might “abuse” it. Don’t let anyone tell you it’s “bad practice” - the Lua designers actually intended and encourage such things (and overriding print is a very common use case, given that Lua is embedded in such a wide variety of environments).
The current reasoning seems a bit like saying that Linux shouldn’t have “rm” because someone might accidentally delete something.
I’d prefer if these sort of “kid gloves” / “protect me from myself” -type features were optional, defaulting to off so as to avoid the type of breaking change as currently being discussed. Developers could then toggle them on for a dev-time check as desired, or off for production. Or just leave it out and let us implement it ourselves as needed (fe, I’ve long used Niklas Frykholm’s GLOBAL_lock() approach)
Apologizes. I was trying to test jwios’s theory in my current codebase earlier in the day, but realized there’s another utility that captures the print and doesn’t output unless a debug flag is set. I just so happened to put that print right before the debug flag was set. Explains why the extra frame is needed to be processed prior to printing. I have edited my last post for anyone scrolling through. The Runtime._G.print is working properly in my case.
Absolutely agree, @davebollinger.
Getting quite sick of stuff (in general!) being ‘dumbed down’, for ‘my own benefit’ when the net result is that I have to do twice as much work to accomplish the same thing to work round it. That appears to be the case with IT in general, since everyone and their dog thinks they can ‘do computers’ now. Yeah - you can ‘do computers’ now because they operate more like a friggin’ toy, and as a side effect, anyone who wants to do anything remotely advanced has to jump through major hoops! Grr.
But being a coder takes a certain discipline, and one of those is ‘this breaks stuff. So don’t do that, k?’…
I don’t care if they switch it on by default for all new projects. But it NEEDS an option to turn it off. I really, really don’t need ‘protecting from myself’ or hand holding. I’ve been coding for 30+ years, coding in lua for 12 years and in Corona since 2009. Sure, still learning all the time… But I do know enough to know how to not ‘shoot myself in the foot’.
What I need is my code to work like it worked before from one build to the next, or all the benefits of Corona become null and void and it’d be a lot safer to code natively, even if we had to maintain multiple codebases for different platforms.