Author Topic: Lua problems and bugs  (Read 11695 times)

0 Members and 2 Guests are viewing this topic.

Offline Loulou 54

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 165
  • Rating: +39/-0
    • View Profile
    • Mes programmes sur TI bank.
Lua problems and bugs
« 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.



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 :)
« Last Edit: August 09, 2011, 08:35:09 am by Loulou 54 »
Some of my program available here.. :)
http://ti.bank.free.fr/index.php?mod=archives&ac=voir2&id=1471

     

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Lua problems and bugs
« Reply #1 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
« Last Edit: August 08, 2011, 12:11:14 pm by Deep Thought »




Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Lua problems and bugs
« Reply #2 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 :)

Offline Loulou 54

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 165
  • Rating: +39/-0
    • View Profile
    • Mes programmes sur TI bank.
Re: Lua problems and bugs
« Reply #3 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.)
« Last Edit: August 08, 2011, 04:39:43 pm by Loulou 54 »
Some of my program available here.. :)
http://ti.bank.free.fr/index.php?mod=archives&ac=voir2&id=1471

     

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Lua problems and bugs
« Reply #4 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.

Offline NecroBumpist

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 130
  • Rating: +14/-5
  • Master of Lua
    • View Profile
Re: Lua problems and bugs
« Reply #5 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
Developing Lua scripts for the NSpire ?
Check out the Necrotorium
Need a few routines to run faster ? Checkout the MODS Lua Assembly Toolkit.
Need to save space for your scripts ? Checkout LuaSrcDiet

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Lua problems and bugs
« Reply #6 on: August 18, 2011, 05:32:34 am »
Ah, didn't know it could be disabled. Thanks :)

Offline Levak

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +208/-39
    • View Profile
    • My website
Re: Lua problems and bugs
« Reply #7 on: August 18, 2011, 05:46:52 am »
2) 3) and 4) will be fixed in future updates. =)
I do not get mad at people, I just want them to learn the way I learnt.
My website - TI-Planet - iNspired-Lua

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Lua problems and bugs
« Reply #8 on: August 18, 2011, 05:49:42 am »
Why 3?
It was a cool way of fetching external data :/

Offline Levak

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +208/-39
    • View Profile
    • My website
Re: Lua problems and bugs
« Reply #9 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.
I do not get mad at people, I just want them to learn the way I learnt.
My website - TI-Planet - iNspired-Lua

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Lua problems and bugs
« Reply #10 on: August 18, 2011, 06:00:34 am »
Oh, so it will become even become better \o/
Thanks for enlightening us :)

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Lua problems and bugs
« Reply #11 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.
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Lua problems and bugs
« Reply #12 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 :'(

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Lua problems and bugs
« Reply #13 on: August 18, 2011, 02:48:22 pm »
Well, it's just 18px ;)
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Levak

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +208/-39
    • View Profile
    • My website
Re: Lua problems and bugs
« Reply #14 on: August 19, 2011, 12:16:49 am »
« Last Edit: August 19, 2011, 12:17:01 am by Levak »
I do not get mad at people, I just want them to learn the way I learnt.
My website - TI-Planet - iNspired-Lua