a = twine('Hello, World!')
function love.draw()
love.graphics.print(a,0,0)
end
'a' is a table. Now, I know that you can't print tables in lua, but I have a '__tostring' metamethod that allows me to print it. So, if I say print(a), it works, but if I tried love.graphics.print, it errors out. Can anyone help me with this? It should be working, as far as I can tell.
I'm not sure of all what arguments can be passed to graphics.print (numbers and strings have worked for me, tables and nil haven't, which makes sense). You're probably better off just tostring()ing it before printing.
Also, for the record, a lot of lua's string methods can be performed on strings directly using the colon syntax:
Kingdaro wrote:I'm not sure of all what arguments can be passed to graphics.print (numbers and strings have worked for me, tables and nil haven't, which makes sense)
IIRC only strings and numbers work since love.graphics.print() ultimately calls the C function lua_tolstring(), and that only accepts strings and numbers.
Kingdaro wrote:
Also, for the record, a lot of lua's string methods can be performed on strings directly using the colon syntax:
]
Yes, I knew that! Thanks I know it is redundant, but why include only the JavaScript string functions, why not include them all?
Also, I have just tried making a ".val()" function so "a.val()" would return it's real value, but then I get a stack overflow error. Any idea? tostring(a), like smile suggested, also gives me a stack overflow error:
20047m wrote:Also, I have just tried making a ".val()" function so "a.val()" would return it's real value, but then I get a stack overflow error. Any idea? tostring(a), like smile suggested, also gives me a stack overflow error:
The __index() metamethod access 'self.value', which invokes the __index() metamethod, which accesses 'self.value', which invokes... And so on. You can instead use rawget(self, "value") to access 'self.value' without triggering any metamethod.