Omnimaga
Calculator Community => TI Calculators => Lua => Topic started by: Loulou 54 on August 08, 2011, 11:32:57 am
-
I haven't found any topic about the different bugs of the Lua language on the TI Nspire.
The goal of this topic is to reference all the problem here and to find solutions or explanations.
(maybe there is already a topic or a place for this, even in another web site as Inspired Lua for example ? If so, please let me know. :) )
So I start with some problem I had or I know.
1) The function string.find(string,substring) produce an error with this substring : "(". If we replace the searchstring by string.uchar(40), this is the same.
The error is "unfinished capture".
Why ??
It seems that this problem occurs only with "(". (If the substring is for example "(g", there is no problem.)
==> How to avoid this ?
* creating a function like this :
function strFind(str,ch)
local chPos
chPos=nil
for i=1,string.len(str) do
if string.sub(str,i,i)==ch and not chPos then
chPos=i
end
end
return chPos
end
* using TI Basic inString( function with Lua math.eval( function.
* string.find(str, "%(")
=> This is the best solution. Thank you jimbauwens. :)
Explications two posts later. :)
2) The graphical bug of Levak :
you can draw in the "status bar", top of the screen.
(http://levak.free.fr/ftp/nspire/Make3D/screens/nspire-emu-3.jpg)
A simple example :
function on.paint(gc)
gc:begin()
-- draw
gc:setFont("sansserif", "b", 10)
gc:drawString("Hello World", 0, 0, "top")
gc:finish()
end
The bug seems to be possible when using gc:begin() / gc:finish instructions.
==> How to avoid this ?
* You don't have to use gc:begin() / gc:finish() generally. ^^
3) (that's not really a problem, but something good to know)
math.eval function runs TI Basic instruction (in a string)
All the instructions seem to work, except :
- I/O functions : Text, Request, RequestStr, Disp
- program call
- Local function
==> How to avoid this ?
* You have to program dialog boxes yourself ! xD
* You can use toolpalette functions for choices.
* You could use D2Editor but.. see 4)
* Instead of calling a basic program, paste all the code into a string in the math.eval( function.
4) The D2Editor seems to be very usefull but we can't remove it ! So you can't really use it..
==> How to avoid this ?
* You have to program yourself a "Request" function.. ^^
Simple example :
msg = ""
function on.paint(gc)
gc:drawString(msg,10,10,"top")
end
function on.charIn(ch)
msg = msg .. ch
platform.window:invalidate()
end
If you want a full code to enter text (delete, clear, insert, go to the fisrt/last character, ...) I can post code from my ABA Logique program ! ^^
So, you can post your potential problems or your solutions/explications.
Thanks :)
-
Another compiled thread, awesome :)
(maybe there is already a topic or a place for this, even in another web site as Inspired Lua for example ? If so, please let me know. :) )
None as far as I know. +1 for useful content
-
Well, the reason for the first 'bug' (it isn't actually a bug) is because "(" is a magic character.
The second argument to string.find is a pattern, so it is parsed as a pattern, and if there is an error in it it will report it. To search for "(" just escape it with "%".
Example:
string.find(str, "%(")
More info on this at http://www.lua.org/pil/20.2.html.
Anyway, nice topic :)
-
Ok ! Thanks Jim ! Wow, the "concept" of pattern is really interesting ! :)
I'll modify the first post.
EDIT : But with ")" (a magic character too) there is no problem.. ^^ (I haven't tried the other magic characters.)
-
Well, maybe ")" is a valid pattern, and doesn't cause an error. I didn't look yet into the details, but I will do that later.
-
string.find() actually has two more parameters.
The first being an integer (can be negative), which describes where to begin searching the string,
The second being a boolean, if true, string patterns are ignored.
print(string.find("herp()", "(", 0, true)) --> 5 5
-
Ah, didn't know it could be disabled. Thanks :)
-
2) 3) and 4) will be fixed in future updates. =)
-
Why 3?
It was a cool way of fetching external data :/
-
Why 3?
It was a cool way of fetching external data :/
I think you didn't understood me =/
Anyway I made a little mistake for this particular case so :
The 3) will be fixed. Understand by that, "Programs and I/O Popups will be handled with math.eval". But "will", understand that not in the next update.
2) and 4) are fixed right now.
-
Oh, so it will become even become better \o/
Thanks for enlightening us :)
-
3) should be improved. I don't know exactly how and in what extent, but it will get better.
-
Too bad 2 will be fixed, though, because the Nyan Cat game will no longer display properly :'(
-
Well, it's just 18px ;)
-
Well, it's just 18px ;)
28px
-
Was the issue directly reported to TI?
-
Was the issue directly reported to TI?
Yes, with many others that we can't provide for now. =)
-
You know that it isn't always to our advantage.
-
You know that it isn't always to our advantage.
What ? the screen bug ? it is a half bug ... if we would be able to draw the entire screen in real time, I don't know if I would have reported it.
-
I thought is was 24 pixels? Either way, the exact size doesn't matter very much.
-
You know that it isn't always to our advantage.
Some bugs that we would have like not to be known by TI were actually fixed by them when I tried with the new version, so we have nothing to regret, there ...
-
Sure, but obviously telling them doesn't help either.
-
I found another problem.
I noticed that we can't use functions like that : function foo(...) return unpack(arg) end.
Maybe that's because of the Lua version...
-
unpack(...) no ?
-
"..." is already unpacked.
So it would just be in your case
function foo(...)
return ...
end
If you want to put "..." in a table just do "{...}".
-
I found another problem.
I noticed that we can't use functions like that : function foo(...) return unpack(arg) end.
Maybe that's because of the Lua version...
Yes, TI has disabled old Lua 5.0 compatible VARARGs.
Not sure why, I always thought that it was a cool feature.