Omnimaga

Calculator Community => TI Calculators => Lua => Topic started by: Loulou 54 on August 08, 2011, 11:32:57 am

Title: Lua problems and bugs
Post 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 :
Code: [Select]
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 :
Code: [Select]
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 :
Code: [Select]
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 :)
Title: Re: Lua problems and bugs
Post by: Deep Toaster on August 08, 2011, 12:03:44 pm
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
Title: Re: Lua problems and bugs
Post by: Jim Bauwens on August 08, 2011, 01:40:31 pm
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 :)
Title: Re: Lua problems and bugs
Post by: Loulou 54 on August 08, 2011, 04:32:32 pm
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.)
Title: Re: Lua problems and bugs
Post by: Jim Bauwens on August 09, 2011, 04:01:30 am
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.
Title: Re: Lua problems and bugs
Post by: NecroBumpist on August 17, 2011, 11:49:12 pm
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
Title: Re: Lua problems and bugs
Post by: Jim Bauwens on August 18, 2011, 05:32:34 am
Ah, didn't know it could be disabled. Thanks :)
Title: Re: Lua problems and bugs
Post by: Levak on August 18, 2011, 05:46:52 am
2) 3) and 4) will be fixed in future updates. =)
Title: Re: Lua problems and bugs
Post by: Jim Bauwens on August 18, 2011, 05:49:42 am
Why 3?
It was a cool way of fetching external data :/
Title: Re: Lua problems and bugs
Post by: Levak on August 18, 2011, 05:55:11 am
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.
Title: Re: Lua problems and bugs
Post by: Jim Bauwens on August 18, 2011, 06:00:34 am
Oh, so it will become even become better \o/
Thanks for enlightening us :)
Title: Re: Lua problems and bugs
Post by: Adriweb on August 18, 2011, 02:40:00 pm
3) should be improved. I don't know exactly how and in what extent, but it will get better.
Title: Re: Lua problems and bugs
Post by: DJ Omnimaga on August 18, 2011, 02:47:56 pm
Too bad 2 will be fixed, though, because the Nyan Cat game will no longer display properly :'(
Title: Re: Lua problems and bugs
Post by: Adriweb on August 18, 2011, 02:48:22 pm
Well, it's just 18px ;)
Title: Re: Lua problems and bugs
Post by: Levak on August 19, 2011, 12:16:49 am
Well, it's just 18px ;)

28px
Title: Re: Lua problems and bugs
Post by: ExtendeD on August 19, 2011, 04:30:57 am
Was the issue directly reported to TI?
Title: Re: Lua problems and bugs
Post by: Levak on August 19, 2011, 04:33:07 am
Was the issue directly reported to TI?

Yes, with many others that we can't provide for now. =)
Title: Re: Lua problems and bugs
Post by: ExtendeD on August 19, 2011, 04:38:00 am
You know that it isn't always to our advantage.
Title: Re: Lua problems and bugs
Post by: Levak on August 19, 2011, 04:45:39 am
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.
Title: Re: Lua problems and bugs
Post by: JosJuice on August 19, 2011, 09:01:22 am
I thought is was 24 pixels? Either way, the exact size doesn't matter very much.
Title: Re: Lua problems and bugs
Post by: Adriweb on August 19, 2011, 09:03:32 am
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 ...
Title: Re: Lua problems and bugs
Post by: ExtendeD on August 19, 2011, 10:23:48 am
Sure, but obviously telling them doesn't help either.
Title: Re: Lua problems and bugs
Post by: Chockosta on September 08, 2011, 11:54:33 am
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...
Title: Re: Lua problems and bugs
Post by: Levak on September 08, 2011, 02:00:27 pm
unpack(...) no ?
Title: Re: Lua problems and bugs
Post by: Jim Bauwens on September 08, 2011, 03:30:25 pm
"..." is already unpacked.
So it would just be in your case
Code: (Lua) [Select]
function foo(...)
  return ...
end

If you want to put "..." in a table just do "{...}".
Title: Re: Lua problems and bugs
Post by: NecroBumpist on September 08, 2011, 11:12:49 pm
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.