Page 2 of 4
Re: LöveOS
Posted: Sat Jun 08, 2013 9:09 am
by qaisjp
JesseH wrote:
I think being able to boot the love games directly would be very cool! I could totally see myself buying a R-Pi just for love games.
Suggestions:
1. I would love to be able to see the possibility of exiting running games and returning to the CLI.
2. The possibility of an overlay CLI using a keybind. Basically everything going on in the booted game is paused and overlayed with the CLI. You could implement this by modifying love.run
Re: LöveOS
Posted: Wed Jun 12, 2013 7:11 am
by Jasoco
Robin wrote:That's pretty neat, but why does it export 23 globals? To wit:
- loveos
- loveos_cmd_num
- loveos_screen_width
- loveos_screen_height
- loveos_start_x
- loveos_start_y
- loveos_font
- loveos_dir
- loveos_cursor_default
- loveos_font_w
- loveos_font_h
- loveos_cursor_x
- loveos_cursor_y
- loveos_cursor_orig
- loveos_cursor
- loveos_backlog_max
- loveos_upper
- loveos_is_letter
- cd
- mkdir
- ls
- rm
- help
Why not put the first batch in the loveos table and why not pass the latter few as arguments to loveos:add_function?
I was just curious. How do you find out what globals are being used by your project? Is there a command that will print out a list of them? I'd be curious to see if I forgot to make some stuff localized.
Re: LöveOS
Posted: Wed Jun 12, 2013 7:19 am
by micha
This should do the job:
Code: Select all
for k in pairs(_G) do
print(k)
end
Re: LöveOS
Posted: Wed Jun 12, 2013 9:48 pm
by Jasoco
micha wrote:This should do the job:
Code: Select all
for k in pairs(_G) do
print(k)
end
Interesting. That works. There's a lot of functions listed there too. (Obviously) I seem to have a lot of globals. Are there any other tips out there? Is there a way to separate the variables from the functions or is Lua so flexible that both are one in the same?
Edit: Thanks to this I have been able to shrink my list of globals down significantly and found some accidental ones. I just wish it would also export what file/line the global was defined on to make it easier to find some of the smaller variables. (Like I have one just called "c". Now I usually use that when calculating a color and I use it locally, but apparently I let one sneak by and it's hard to find because I can't figure out how to use text search to find just a c that's a variable and not part of another word. I'm sure there's a way using grep, but I don't know how grep works at all.)
Re: LöveOS
Posted: Thu Jun 13, 2013 2:50 pm
by Plu
There's no difference between a function and a variable in concept, but you can test which of the two it is by using
At least I think the return would be 'function', I could be wrong
But you need the type(x) function.
Re: LöveOS
Posted: Thu Jun 13, 2013 3:08 pm
by micha
Jasoco wrote:I just wish it would also export what file/line the global was defined on to make it easier to find some of the smaller variables.
I haven't tried myself, but I have the vague idea, that this might work with metatables and the __newIndex metamethod. See in
PiL. With that you can define a function that is called, whenever a global variable is set or updated. That way at least you can detect
when a global variable is created.
Re: LöveOS
Posted: Thu Jun 13, 2013 7:02 pm
by bartbes
You mean like..
strict.lua?
Re: LöveOS
Posted: Fri Jun 14, 2013 3:52 am
by Jasoco
Plu wrote:There's no difference between a function and a variable in concept, but you can test which of the two it is by using
At least I think the return would be 'function', I could be wrong
But you need the type(x) function.
Doesn't work. They're all stored as strings in the _G table.
I wish there was a way to get an exclusion list of functions that are part of Lua, which are part of Löve and which are part of my project.
I don't.. know how to use that at all. Or what it does.
Sorry to take this off track. Maybe someone can split this stuff starting with my question off into its own thread. I only asked out of curiosity really. From a user standpoint I wasn't even concerned about loose globals, but everyone seems to make a big deal about leaky variables so I thought I'd do some cleaning up. But the _G list is really plain. Just a table full of strings that are names of variables and functions. No other metadata at all.
Re: LöveOS
Posted: Fri Jun 14, 2013 5:30 am
by Wojak
Jasoco wrote:Plu wrote:There's no difference between a function and a variable in concept, but you can test which of the two it is by using
At least I think the return would be 'function', I could be wrong
But you need the type(x) function.
Doesn't work. They're all stored as strings in the _G table.
Code: Select all
for k,f in pairs(_G) do
print(k..", type: "..type(f))
end
Re: LöveOS
Posted: Fri Jun 14, 2013 5:32 am
by micha
Jasoco wrote:Plu wrote:There's no difference between a function and a variable in concept, but you can test which of the two it is by using
At least I think the return would be 'function', I could be wrong
But you need the type(x) function.
Doesn't work. They're all stored as strings in the _G table.
The keys are all strings, but the values have different types. Try this loop:
Code: Select all
for k,v in pairs(_G) do
print(k .. ' is of type ' .. type(v))
end