Question Lua print() function and Lua libraries?

dmurley

New member
Joined
Dec 11, 2017
Messages
37
Reaction score
0
Points
0
Location
Hill country (near San Antonio
Does the Lua print() function not work in the Lua console (in Orbiter) because that console is not defined as stdout?

Are the Lua libraries generally available?

Thanks.
 

kuddel

Donator
Donator
Joined
Apr 1, 2008
Messages
2,064
Reaction score
507
Points
113
What do you expect that function to do? And why not just roll your own...

For just a "shortcut" to term.out() :
Code:
function print (s)
  term.out(s)
end

For a more (C library) sprintf like behaviour:
Code:
function printf (fmt, ...)
  term.out(string.format(fmt, unpack(arg)))
end

If you are planning to use it/them in multiple scripts, put it in a Lua-file under "Scripts/" under a "catchy" name (e.g. "my_lib.lua").
Then you can "include" the definitions/declarations in your Lua script via:
Code:
run('my_lib')
-- ... your code using it goes here ...

Although, those "one-liners" would barely make it a "Library" :lol:

And I don't think these should be made "Orbiter-standard", as the current functionality is enough to do the things one has to do with a fairly small amount of extra work.
Second, these print functions are only useful in an terminal-environment; by using a member of term, it is obvious for any reader of the script where it goes...
 

dmurley

New member
Joined
Dec 11, 2017
Messages
37
Reaction score
0
Points
0
Location
Hill country (near San Antonio
Just studying Lua and am curious

Just studying Lua and wondering what happened to print(). I realize that I can use term.out() instead (which I will instead of recreating a print function), but that doesn't help me understand what is happening here.

Also, are the other Lua libraries generally available?
 

kuddel

Donator
Donator
Joined
Apr 1, 2008
Messages
2,064
Reaction score
507
Points
113
What exactly do you mean by "[...]are the other Lua libraries generally available"?

If you like to know if the Standard Libraries as of chapter 5 of the Lua documentation are available in Orbiter, then: yes they are (with minor exceptions maybe).

The Lua core used in Orbiter is basically Lua 5.1 in all it's glory :p

Some few features might not be available, but I have no knowledge of them.
Also no reason not to try and see if they work.

If some specific functionality is not working, you can ask for that specific issue and we might give you an explanation why (or why not).

Lua by the way is more of a way to access Orbiter's API through a scripting language, not so much about a Feature-Rich-Library-Collection (like .NET e.g.)
 
Last edited:
Top