Omnimaga

Calculator Community => TI Calculators => Lua => Topic started by: hellninjas on December 29, 2011, 11:57:49 pm

Title: Getting started with Lua on Nspire
Post by: hellninjas on December 29, 2011, 11:57:49 pm
Okay, I would like to learn how to code Lua on an nspire!
My OS is 3.1.0.392
I would really like to learn how to make menu's...
Also making pictures... and many moar things in Lua!
Please help!
Thanks!
Title: Re: Nspire Basic
Post by: willrandship on December 30, 2011, 12:07:18 am
No menus on the nspire
XXX->Varname (up to 16 chars IIRC) and that can be literally anything from matrices to strings to ints to floats
no way to display pics directly. Plotting points can be a method that takes forever. Also, there's no output command.

The best way I've found to do any sort of proper display method was the text box, or regular disp with matrices.

You should also become VERY familiar with the string commands:

Left()
Mid()
right()
str & str
instring()

See the nspire catalog for a syntax example. Left takes a number of chars starting from the left of a string and returns that substring. same goes for right. Mid is identical to the 84+ sub(). & is the equivalent of str+str in 84+ basic. Instring finds the position of one string inside of another, and returns a particular int (0 I think) if it doesn't find any. It gives the first one then stops, so multiples are undetected.

request and requeststr are the only ways of getting in-prog input, but there are also inline args when you run the program. ex. prog(a,b,c) where a b and c are vars of any type that become vars in your program.

Local var is a great way of avoiding variable collisions between progs, it makes it so a var doesn't affect a var by the same name outside the program. Example:

Out of program:
6->a

in program:
local a
"hello"->a
end program:

disp a
 - Returns 6

No way to exit PTT from basic :P that's one of the many uses for ndless. besides, you can't run basic progs from within PTT anyways, unless you make them on the spot.

I probably got one or two things wrong, but that's about as far as BASIC can go while remaining inside one program. If you're not afraid of using multiple programs
Title: Re: Nspire Basic
Post by: hellninjas on December 30, 2011, 12:12:37 am
No menu's eh?
Ndless it is...
Is there an Ndless for OS 3.1.0.392?
Title: Re: Nspire Basic
Post by: willrandship on December 30, 2011, 12:14:55 am
not yet ;) but there's already a closed beta, so it can't be very far off.

Have you considered Lua? It's much better, being a real language and all. Not to mention faster. AND it can be programmed on-calc if you send the right progs.
Title: Re: Nspire Basic
Post by: hellninjas on December 30, 2011, 12:17:03 am
How would I do this? It sounds like a nice idea :D
Nice Prof Pic btw... xD
Title: Re: Nspire Basic
Post by: willrandship on December 30, 2011, 12:21:35 am
hehe yeah...:P

TI was nice and gave us Lua to use on OSes above 2.1. I don't know much about it, but there's a ton of people on this forum who do (I stuck to 2.1 so I could keep ndless, but with ndless 3 I'll switch)

Also, you actually posted in the Lua subforum :P Change the title to "Getting started with Lua" or something similar and you'll be all set.
Title: Re: Getting started with Lua on Nspire
Post by: hellninjas on December 30, 2011, 12:31:18 am
Done!
Thankx for teh reccomendation!
I can't wait for Lua! :D
Title: Re: Getting started with Lua on Nspire
Post by: jwalker on December 30, 2011, 12:55:18 am
to make pictures, you can use all of the drawing commands, or you can convert a pic to a ti.image although this is realy large and re-drawing the screen will slow down
to make a menu...if you ever read the tibasicdev article on making custom menus thats basicly what you would have to do it in lua, as there isnt a
"Menu(" command
Lua is realy easy to learn everything is event/function based
Lua example:
Code: [Select]
function on.paint(gc)
    gc:setColorRGB(0, 0, 0)--set the color to black
    gc:drawRect(3, 3, 50, 50)--draws a rectangle on the screen with black lines
    gc:fillRect(100, 0, 50, 50)--makes a rectangle that is filled with the color black
end
to find some tutorials go to: http://www.inspired-lua.org/ (http://www.inspired-lua.org/)
to get the official scripting tools go to: http://education.ti.com/educationportal/sites/US/nonProductSingle/nspire-scripting.html (http://education.ti.com/educationportal/sites/US/nonProductSingle/nspire-scripting.html)
Title: Re: Getting started with Lua on Nspire
Post by: epic7 on December 30, 2011, 12:57:17 am
I can't wait for Lua! :D
Why wait? :P

Also, can you make sprites in lua?
Title: Re: Getting started with Lua on Nspire
Post by: jwalker on December 30, 2011, 01:15:33 am
you could make sprites, i would suggest using classes, but you would have to use one of the two methods i talked about above for drawing them
Title: Re: Getting started with Lua on Nspire
Post by: Jim Bauwens on December 30, 2011, 04:15:30 am
There is TI.Image, no need to create your own routine for that.
You just need img=image.new(data) to create the sprite, and gc:drawImage(img,x,y) to draw it.

Edit, misunderstood your previous post. TI.Image isn't to slow if you use it wisely ;)
Title: Re: Getting started with Lua on Nspire
Post by: Adriweb on December 30, 2011, 04:38:53 am
and it will be even faster soon ;)
Title: Re: Getting started with Lua on Nspire
Post by: jwalker on December 30, 2011, 10:52:07 am
well thats good to know that it will be faster and i wasnt that clear either, i should have put in my post the larger they are- the more that everything lags when its redrawing
Title: Re: Getting started with Lua on Nspire
Post by: hellninjas on December 30, 2011, 02:06:54 pm
I see alot of people coding on the computer and transfering to the calc, but how would I program ON-Calc ?
Title: Re: Getting started with Lua on Nspire
Post by: cyanophycean314 on December 30, 2011, 03:40:55 pm
You can use the default notes application and then copy and paste to oclua or you can use LuaCS and copy to paste to Oclua.

For on-calc sprites, you can use Chockosta's nSpaint.

You can't really get .tns oncalc, at least I don't think so...
Title: Re: Getting started with Lua on Nspire
Post by: Adriweb on December 30, 2011, 03:49:59 pm
You can't really get .tns oncalc, at least I don't think so...

Maybe if a ndless program could parse the xml (of the Lua code) that would be inside the .tns and extract it to create a script widget like Luna does ... but this could be quite difficult.
Title: Re: Getting started with Lua on Nspire
Post by: Jim Bauwens on December 30, 2011, 04:37:33 pm
What about just finding the right syscalls to the functions the OS uses?
Title: Re: Getting started with Lua on Nspire
Post by: Adriweb on December 30, 2011, 04:42:01 pm
What about just finding the right syscalls to the functions the OS uses?

What ???
:o
Title: Re: Getting started with Lua on Nspire
Post by: hellninjas on December 30, 2011, 05:00:54 pm
Using the Oclua calc thingy, would I be able to save after I copied and pasted?
Title: Re: Getting started with Lua on Nspire
Post by: Jim Bauwens on December 30, 2011, 06:11:42 pm
What about just finding the right syscalls to the functions the OS uses?

What ???
:o
Well, the OS can decode, encode documents. If you could find the functions that handle this it will be more easy.
Title: Re: Getting started with Lua on Nspire
Post by: jwalker on December 30, 2011, 07:38:42 pm
you could save the notes page that you made your code in
Title: Re: Getting started with Lua on Nspire
Post by: ExtendeD on December 31, 2011, 04:04:45 am
The whole OpenSSL library is included in the OS so porting Luna would probably be easier. And the OS validation of the PK-ZIP format is actually quite weak so minizip isn't really needed.
Title: Re: Getting started with Lua on Nspire
Post by: Adriweb on December 31, 2011, 04:06:11 am
The whole OpenSSL library is included in the OS so porting Luna would probably be easier. And the OS validation of the PK-ZIP format is actually quite weak so minizip isn't really needed.
Great :)
That's a good ndless project then, for anyone who has some time to spend on that :P
Title: Re: Getting started with Lua on Nspire
Post by: willrandship on January 01, 2012, 03:19:41 am
Umm, all files on the calc are .tns files :P they may not follow the .tns guideline, but even your gameboy roms from gbc4nspire are .tns files.

Argh page turn fail.

What I'd really love is mimas-style asm programming on-calc. that would totally rock, especially since a ram clear doesn't affect you in the slightest! A crashing program can have literally no effect on the others, since everything is basically in the archive!
Title: Re: Getting started with Lua on Nspire
Post by: Ghezra on March 04, 2012, 12:17:13 pm
At certain times I had large imgSRCs loading on the screen, what I found is that you can cut down the time it takes to refresh the screen dramatically if you have it to where it draws the image, and then only refresh sections of the screen that are changing with the functions.

Check out http://wiki.inspired-lua.org/platform.window:invalidate
Title: Re: Getting started with Lua on Nspire
Post by: Jonius7 on March 04, 2012, 08:19:10 pm
Wow great discussion here.
Yeah nspire BASIC is really limited, though you can make "menu" based games where you select particular commands/programs to run. Graphing stuff is limited though, but there are some things you can do with changing variables in programs.