raidho36 wrote: ↑Sun May 19, 2019 10:39 am
It's a common practice to call the class to create new instances of the class, provided "__call" metamethod is defined. It's equivalent of calling class:new but uses Lua builtin dispatch system instead of actually calling "new" manually.
Right. My confusion is not about technical details, but about the semantics in your example.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
You forgot the most important step though!
Don't assume the error message is actually accurate; print out the iter count where it failed!
Edit: unless that 201 is that...
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
$ luajit
LuaJIT 2.0.4 -- Copyright (C) 2005-2015 Mike Pall. http://luajit.org/
JIT: ON CMOV SSE2 SSE3 SSE4.1 fold cse dce fwd dse narrow loop abc sink fuse
> s = "" for i = 1, 201 do s = s .. " local x" end assert(loadstring(s))
stdin:1: [string " local x local x local x local x local x loca..."]:1: main function has more than 200 local variables
stack traceback:
[C]: in function 'assert'
stdin:1: in main chunk
[C]: at 0x55d307a636c0
> s = "" for i = 1, 200 do s = s .. " local x" end assert(loadstring(s))
> s = "" for i = 1, 199 do s = s .. " local x" end
> s2 = s .. " do local x ; local x end" assert(loadstring(s2))
stdin:1: [string " local x local x local x local x local x loca..."]:1: main function has more than 200 local variables
stack traceback:
[C]: in function 'assert'
stdin:1: in main chunk
[C]: at 0x55d307a636c0
> s2 = s .. " do local x end ; do local x end" assert(loadstring(s2))
>
In the last case there are more than 200 but not all active at the same time.
I just manually plopped a load of locals and indeed it's capped at 200. Note that upvalues are not locals.
grump wrote: ↑Sun May 19, 2019 2:30 pm
Common sense says that class() returns a class, but you named them 'instance'.
Why would class ( ) return class? "__call = function ( t ) return t end"? That would be pointless. As I said, calling class object itself is equivalent to calling class:new, if you have appropriate metamethod set up. A class library object would return a blank class if you call it (or :new) but that's not what happens here.
raidho36 wrote: ↑Sun May 19, 2019 9:33 pm
Why would class ( ) return class?
I'd expect class to return a(!) class, from which you subsequently create instances. There's code in my reply that illustrates my point. It's not about metamethods; it's about the difference between classes and instances/objects.
Edit: Ooh, sorry, I think I finally get you now. Your class is not a function that creates a class as one would naturally assume, it's rather an actual class that's just named "class" and it takes a string argument in its constructor? It's the only way all of this would make any sense, just very unfortunate naming, lol. This is why it's advisable to follow the usual conventions and start your class/type names with an uppercase letter, it prevents this kind of confusion from happening even when you don't know the exact definition behind an identifier.