Function from Lua: os.date()

The Standard Libraries of Lua

Information and discussion for custom maps and mods.
Post Reply
Adrian
Posts: 50
Joined: Wed Feb 12, 2020 5:44 pm

Function from Lua: os.date()

Post by Adrian »

I read about Lua in general now. About the Standard Libraries.
Here is a chapter "Date and Time":
https://www.lua.org/pil/22.1.html

I try to use function os.date(). It must return string or table with date and/or time data.
Can I use this function in any game lua files?

I try to write like this:
vrem = os.date()
or even copy example of table from manual
temp = os.date("*t", 906000490)
and this does not work.

Fatal Lua Error: [string "atreides03a.lua"]:196: attempt to call field 'date' (a nil value)

abcdefg30
Posts: 445
Joined: Mon Aug 18, 2014 6:00 pm

Re: Function from Lua: os.date()

Post by abcdefg30 »

Most os functions are blocked by the sandbox, so it looks like this is sadly not usable.

Adrian
Posts: 50
Joined: Wed Feb 12, 2020 5:44 pm

Re: Function from Lua: os.date()

Post by Adrian »

Thank you.
I read about tables now. About table.concat().
http://lua-users.org/wiki/TableLibraryTutorial

This is example for command line. And it work in my command line, Lua 5.1.5.

Code: Select all

> = table.concat({ 1, 2, "three", 4, "five" })
12three4five
It returns one string from all table values.

Can it work in OpenRa?
Or another way to turn all table values to string?

abcdefg30
Posts: 445
Joined: Mon Aug 18, 2014 6:00 pm

Re: Function from Lua: os.date()

Post by abcdefg30 »

I don't think the 'table' function is blocked by our sandbox, so I'd just try if that works in OpenRA. Otherwise you'll need to iterate over the table contents in a for loop and concat "manually".

Adrian
Posts: 50
Joined: Wed Feb 12, 2020 5:44 pm

Re: Function from Lua: os.date()

Post by Adrian »

I don't think the 'table' function is blocked by our sandbox, so I'd just try if that works in OpenRA.
I tried. OpenRA returns nearly the same error (as os.date) for table.concat too.
[string "harkonnen09b.lua"]:547: attempt to call field 'concat' (a nil value)

So I thought, may be I must include some libraries to activate these functions... May be no.
Otherwise you'll need to iterate over the table contents in a for loop and concat "manually".
Anyway, it was not very difficult to write it by myself. Thanks for your advise about "for".
I supposed to do this with "foreach". But "for" is quite good for this aim.

Matt
Posts: 1066
Joined: Tue May 01, 2012 12:21 pm
Location: Germany

Re: Function from Lua: os.date()

Post by Matt »

Those functions have to be added there https://github.com/OpenRA/OpenRA/blob/8 ... ua#L51-L72 they are currently not whitelisted, but they do sound safe.

Post Reply