Author Topic: Add function to the gc class  (Read 26771 times)

0 Members and 1 Guest are viewing this topic.

Offline Frog

  • LV2 Member (Next: 40)
  • **
  • Posts: 35
  • Rating: +0/-0
    • View Profile
Re: Add function to the gc class
« Reply #30 on: September 09, 2011, 05:37:15 am »
But why can I then get platform.window.screen when I set it using window.screen? And platform.window does have methods, doesn't that mean it is actually a table? Also, I can get the metatable, doesn't that mean the same?

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Add function to the gc class
« Reply #31 on: September 09, 2011, 01:21:29 pm »
The metatable is not the same like the object itself, but you can use it in this case.
I tried this, and it works:
Code: (Lua) [Select]
window = getmetatable(platform.window)
window.screen = 123
platform.window.screen will then have the value 123.

Offline Frog

  • LV2 Member (Next: 40)
  • **
  • Posts: 35
  • Rating: +0/-0
    • View Profile
Re: Add function to the gc class
« Reply #32 on: September 09, 2011, 01:24:21 pm »
Sorry, maybe I wasn't clear enough. I understand that works, but why does it work? Why can't I just set the screen using platform.window.screen? That's more logical...

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Add function to the gc class
« Reply #33 on: September 09, 2011, 01:26:28 pm »
platform.window itself is not a table, but userdata. userdata is controlled from C, and we can't touch it. Thats why we use the metatable of it :)

Offline Frog

  • LV2 Member (Next: 40)
  • **
  • Posts: 35
  • Rating: +0/-0
    • View Profile
Re: Add function to the gc class
« Reply #34 on: September 09, 2011, 01:39:32 pm »
Owh okay, thanks a lot again! This helped me a lot. May I ask how you know this? I couldn't find anything on it... Or did you take a detailed look at the OS installation files?

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Add function to the gc class
« Reply #35 on: September 09, 2011, 01:41:11 pm »
I didn't look at the os files ;)
I just scan, search and poke through the Lua environment because I love to do that so much :)

Offline Frog

  • LV2 Member (Next: 40)
  • **
  • Posts: 35
  • Rating: +0/-0
    • View Profile
Re: Add function to the gc class
« Reply #36 on: September 09, 2011, 01:45:43 pm »
But how does that work? ??? Do you output the _G variable?

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Add function to the gc class
« Reply #37 on: September 09, 2011, 01:49:24 pm »
_G is a table and contains everything.
We just loop through the table recursively and check the types of stuff.
Here is an example of a dump: http://paste.bwns.be/p/m22cc805b.

Offline Frog

  • LV2 Member (Next: 40)
  • **
  • Posts: 35
  • Rating: +0/-0
    • View Profile
Re: Add function to the gc class
« Reply #38 on: September 09, 2011, 01:56:26 pm »
Wow, so that's how you found out about every function. One last question: how did you create this dump? I have been trying to output a really big table I created for debugging purposes, but I can't find a good method since I can only use gc:drawString. Is there a different method? The print() output isn't showed anywhere...

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Add function to the gc class
« Reply #39 on: September 09, 2011, 02:01:07 pm »
With 3.01 and 3.02, print outputted to the computer console with the computer software, and to the serial port with the calculator.
However the day before yesterday TI released a new OS, and they made that print() isn't functional anymore. This is probably because they didn't like thing that we did with it (controlling external hardware, outputting sound)
Anyway, what we did was make a fake print function that puts everything in a string, and then we put it in the clipboard using clipboard.addText. Then we pasted it, and we got the dump :)

Offline Frog

  • LV2 Member (Next: 40)
  • **
  • Posts: 35
  • Rating: +0/-0
    • View Profile
Re: Add function to the gc class
« Reply #40 on: September 09, 2011, 02:12:24 pm »
Wow, that's smart! :o I've still got 3.01 on my nSpire CX and 3.02 on my desktop software. Is there an easy way to get the print output (either on the desktop or calculator)? Could you maybe add the custom print() function to the inspired-lua wiki?

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Add function to the gc class
« Reply #41 on: September 09, 2011, 02:38:01 pm »
Try running the software from cmd, and look at the output when running a lua script with print(). You should see it in the console :)

And yes, I could put the print functions we created on inspired-lua :D
« Last Edit: September 09, 2011, 02:39:52 pm by jimbauwens »

Offline Frog

  • LV2 Member (Next: 40)
  • **
  • Posts: 35
  • Rating: +0/-0
    • View Profile
Re: Add function to the gc class
« Reply #42 on: September 09, 2011, 02:45:00 pm »
Yeah, it would be great if you put it on inspired-lue!

I can't use the cmd, because I'm using a mac. I didn't find a way to run the TI-Nspire software from the terminal, or are you talking about the third-party emulator for windows?

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Add function to the gc class
« Reply #43 on: September 09, 2011, 05:11:29 pm »
You can run the mac version from the terminal, but I don't know right away how to do that.
Lemme poke someone who knows it :)

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Add function to the gc class
« Reply #44 on: September 09, 2011, 05:16:52 pm »
Yeah, it would be great if you put it on inspired-lue!

I can't use the cmd, because I'm using a mac. I didn't find a way to run the TI-Nspire software from the terminal, or are you talking about the third-party emulator for windows?

You have to browse to where you installed the software.

Then right-click the app -> Show Package Contents -> open the "Contents" folder -> go to the "MacOS" folder, and drag and drop the JavaApplicationSTub file to a terminal window
Then press Enter on that terminal window
all the debugging output will be printed into the console instead of logs and/or /dev/null or seomthing.

Screenshot :
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation