Author Topic: Lua Q&A  (Read 104237 times)

0 Members and 1 Guest are viewing this topic.

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Lua Q&A
« Reply #30 on: July 25, 2011, 01:32:06 am »
ephan, I have the basis of a game, with smooth scrolling. Its actually intended for the contest, but I haven't had much time to work on it :(

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Lua Q&A
« Reply #31 on: July 26, 2011, 12:31:50 pm »
I've made a almost-100%-smooth scrolling engine for a game I wanted to make... it worked pretty well but the game I wanted to make (jumping arcade game, with buildings scrolling, and the character had not to fall between the randomly generated buildings) didn't get really far, so....

Maybe I can find some scrolling functions I have in my backups ... %)
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline 3rik

  • LV3 Member (Next: 100)
  • ***
  • Posts: 92
  • Rating: +8/-0
  • My TI-84+ SE
    • View Profile
Re: Lua Q&A
« Reply #32 on: August 14, 2011, 01:34:55 am »
Does anyone know what the function image.__gc does? When I try to paste code including image.__gc() into the student software, the software closes. I have no idea what this function does. There isn't anything useful in the mere 87 results I had on Google when I searched "image.__gc". When I searched __gc most of it was C++ stuff.
Userbars

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Lua Q&A
« Reply #33 on: August 14, 2011, 03:51:58 am »
It's probably a meta method, and is probably not ment to be used in normal scripts :)

Offline 3rik

  • LV3 Member (Next: 100)
  • ***
  • Posts: 92
  • Rating: +8/-0
  • My TI-84+ SE
    • View Profile
Re: Lua Q&A
« Reply #34 on: August 14, 2011, 12:03:14 pm »
Thanks. That would probably explain the lack of documentation on it. I'm still curious why the student software just closes instead of giving an error message or something.
Userbars

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Lua Q&A
« Reply #35 on: August 14, 2011, 12:41:49 pm »
Well, my guess is that the variable doesn't do error checking, and triggers a reset/crash when invalid parameters are passed.

Offline 3rik

  • LV3 Member (Next: 100)
  • ***
  • Posts: 92
  • Rating: +8/-0
  • My TI-84+ SE
    • View Profile
Re: Lua Q&A
« Reply #36 on: August 14, 2011, 12:48:05 pm »
If that's the case then I'm glad I didn't try to send it to my calculator.
« Last Edit: August 14, 2011, 12:50:00 pm by 3rik »
Userbars

Offline NecroBumpist

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 130
  • Rating: +14/-5
  • Master of Lua
    • View Profile
Re: Lua Q&A
« Reply #37 on: August 17, 2011, 11:51:13 pm »
Does TI utilize LuaJIT (not sure if the ARM port is compatible with this processor) ?
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 Levak

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +208/-39
    • View Profile
    • My website
Re: Lua Q&A
« Reply #38 on: August 17, 2011, 11:58:16 pm »
I don't know, have you got a specific pattern or clue that could help us to determine if it is used ?
I do not get mad at people, I just want them to learn the way I learnt.
My website - TI-Planet - iNspired-Lua

Offline NecroBumpist

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 130
  • Rating: +14/-5
  • Master of Lua
    • View Profile
Re: Lua Q&A
« Reply #39 on: August 18, 2011, 12:25:27 am »
Okay, I can't find my Nspire, and I've yet to update it to 3.0, so if any one can run the following code for me, that would be wonderful.

Code: [Select]
local function test(...)
    if arg then
         print("Lua") -- might have to replace print() with a graphics API call, I haven't use it yet
    else
         print("LuaJIT");
    end
end

test(1, true, 'cool');

LuaJIT handles variable argument functions differently than normal Lua, which is why the above would discern the two.
Sorry, but I don't know the graphics API, as I said, I've yet to start messing around  :)

Also, did TI keep the loadstring() function, or did they clear that out for security reasons ?
If they kept it, it opens the doors for at least one potential exploit, and the possibility of optimized Lua assembly (though TI-Basic is still probably faster)
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 Levak

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +208/-39
    • View Profile
    • My website
Re: Lua Q&A
« Reply #40 on: August 18, 2011, 12:34:21 am »
It returns "LuaJIT"

I'm quite interesting by this, but I don't understand this sentence :
Quote
LuaJIT handles variable argument functions differently than normal Lua, which is why the above would discern the two.
Sorry, but I don't know the graphics API, as I said, I've yet to start messing around

Can you explain a little bit more (as you're there :D)


Quote
Also, did TI keep the loadstring() function, or did they clear that out for security reasons ?
If they kept it, it opens the doors for at least one potential exploit, and the possibility of optimized Lua assembly (though TI-Basic is still probably faster)
It is present, yes =)
« Last Edit: August 18, 2011, 12:34:53 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

Offline NecroBumpist

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 130
  • Rating: +14/-5
  • Master of Lua
    • View Profile
Re: Lua Q&A
« Reply #41 on: August 18, 2011, 12:46:35 am »
Good, TI finally made a smart decision.  :D
LuaJIT is insanely fast compared to normal Lua.

Quote
Can you explain a little bit more (as you're there )

Having "..." as a function parameter will cause that function to accept any number of inputs.
Lua 5.0.* (I think) was the last version to official support converting of variable arguments into a table which is automatically localized (the 'arg' variable).
Lua 5.1.4 has compatibility with this feature, LuaJIT does not by default (I think you can enable it).

While this is good news for speed, it's bad news for the one exploit I mentioned, as LuaJIT uses a different bytecode format, and the exploit probably isn't viable.
Not to mention I've been working on a complex Lua assembler for other things and when I saw NSpire 3 uses Lua I got excited, but I guess that won't be of much use here  :'(
« Last Edit: August 18, 2011, 12:52:49 am by NecroBumpist »
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 Levak

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +208/-39
    • View Profile
    • My website
Re: Lua Q&A
« Reply #42 on: August 18, 2011, 12:55:45 am »
Having "..." as a function parameter will cause that function to accept any number of inputs.
Lua 5.0.* (I think) was the last version to official support converting of variable arguments into a table which is automatically localized (the 'arg' variable).
Lua 5.1.4 has compatibility with this feature, LuaJIT does not by default (I think you can enable it).

Ok, I see now, thanks for the tip =)
I do not get mad at people, I just want them to learn the way I learnt.
My website - TI-Planet - iNspired-Lua

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: Lua Q&A
« Reply #43 on: August 18, 2011, 02:30:26 am »
TI does not use LuaJIT:
* the first optimized ARM release occurred months after TI started working on Lua in the Nspire OS 3.x;
* LuaJIT is likely to have fixes for the Lua 5.1.4 bugs, while TI's implementation in OS 3.0.1.1753 remained unfixed, see http://ourl.ca/10472 .
Even with a JIT, Lua would remain very far from being a substitute to native code, in terms of both power (expressiveness) and speed.

Some people have expressed worries that if we get native code access (which is perfectly in our right to use the hardware we bought the way we see fit) through Lua, the anti-programmation subset of the management at TI would shut the door on Lua.
But more than four months into Lua programming on the Nspire, and after the making of many programs that dramatically improve the functionality of the Nspire for both educational and gaming uses, it's probably way too late to do that, though... unless they're crazy enough to go the Sony way, and motivate reverse-engineering with a goal of revenge and ghastly attacks on the business model...
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline NecroBumpist

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 130
  • Rating: +14/-5
  • Master of Lua
    • View Profile
Re: Lua Q&A
« Reply #44 on: August 18, 2011, 10:43:31 am »
Huh, I guess they must have modified Lua. And that's a good point about the LuaJIT ARM release date, I hadn't even though about that.

Welp,
I dare someone to go run this on their calculator (likely to segfault):
Code: [Select]
loadstring(('').dump(function()X''end):gsub('\2%z%z%zX','\0\0\0'))()

The above is just one of many problems with Lua's bytecode implementation.
I guess now I'll go load OS 3 onto mine, and experiment with a few other bytecode exploits I know of.

Thanks for the info Lionel.
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