## LöveOS

qaisjp
Party member
Posts: 489
Joined: Tue Sep 04, 2012 10:49 am
Location: United Kingdom
Contact:

### Re: LöveOS

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
Lua is not an acronym.

Jasoco
Inner party member
Posts: 3641
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

### Re: LöveOS

Robin wrote:That's pretty neat, but why does it export 23 globals? To wit:
1. loveos
2. loveos_cmd_num
3. loveos_screen_width
4. loveos_screen_height
5. loveos_start_x
6. loveos_start_y
7. loveos_font
8. loveos_dir
9. loveos_cursor_default
10. loveos_font_w
11. loveos_font_h
12. loveos_cursor_x
13. loveos_cursor_y
14. loveos_cursor_orig
15. loveos_cursor
16. loveos_backlog_max
17. loveos_upper
18. loveos_is_letter
19. cd
20. mkdir
21. ls
22. rm
23. 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.

micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

### Re: LöveOS

This should do the job:

Code: Select all

for k in pairs(_G) do
print(k)
end

Jasoco
Inner party member
Posts: 3641
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

### Re: LöveOS

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.)

Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

### Re: LöveOS

There's no difference between a function and a variable in concept, but you can test which of the two it is by using

Code: Select all

if( type(x) == 'function' )

end

At least I think the return would be 'function', I could be wrong But you need the type(x) function.

micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

### Re: LöveOS

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.

bartbes
Sex machine
Posts: 4944
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

### Re: LöveOS

You mean like.. strict.lua?

Jasoco
Inner party member
Posts: 3641
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

### Re: LöveOS

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

Code: Select all

if( type(x) == 'function' )

end

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.
bartbes wrote:You mean like.. strict.lua?
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.

Wojak
Party member
Posts: 134
Joined: Tue Jan 24, 2012 7:15 pm

### Re: LöveOS

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

Code: Select all

if( type(x) == 'function' )

end

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

micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

### Re: LöveOS

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

Code: Select all

if( type(x) == 'function' )

end

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

### Who is online

Users browsing this forum: Exabot [Bot] and 5 guests