-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
552 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
API docs for Space Lua's `js` module, which provides JavaScript interoperability. | ||
|
||
## js.import(url) | ||
Imports a JavaScript module from a URL. Returns the imported module. | ||
|
||
Example: | ||
```lua | ||
-- Import lodash library | ||
local lodash = js.import("https://esm.sh/lodash@4.17.21") | ||
local result = lodash.chunk({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 3) | ||
|
||
-- Import moment.js for date handling | ||
local moment = js.import("https://esm.sh/moment@2.30.1") | ||
local day = moment("1995-12-25") | ||
print(day.format("DD-MM-YYYY")) -- prints: 25-12-1995 | ||
``` | ||
|
||
## js.new(constructor, ...) | ||
Creates a new instance of a JavaScript class. Takes a constructor function and its arguments. | ||
|
||
Example: | ||
```lua | ||
local Date = js.import("https://esm.sh/date-fns") | ||
local date = js.new(Date, "2024-03-14") | ||
``` | ||
|
||
## js.stringify(value) | ||
Converts a Lua value to a JSON string representation. | ||
|
||
Example: | ||
```lua | ||
local data = {1, 2, 3} | ||
print(js.stringify(data)) -- prints: [1,2,3] | ||
|
||
local nested = lodash.chunk({1, 2, 3, 4, 5, 6}, 2) | ||
print(js.stringify(nested)) -- prints: [[1,2],[3,4],[5,6]] | ||
``` | ||
|
||
## js.tolua(value) | ||
Converts a JavaScript value to its Lua equivalent. | ||
|
||
Example: | ||
```lua | ||
local jsArray = someJsFunction() | ||
local luaTable = js.tolua(jsArray) | ||
``` | ||
|
||
## js.tojs(value) | ||
Converts a Lua value to its JavaScript equivalent. | ||
|
||
Example: | ||
```lua | ||
local luaTable = {1, 2, 3} | ||
local jsArray = js.tojs(luaTable) | ||
``` | ||
|
||
## js.log(...) | ||
Logs messages to the JavaScript console. | ||
|
||
Example: | ||
```lua | ||
js.log("Debug message") | ||
js.log("User data:", {name = "John", age = 30}) | ||
``` | ||
|
||
## js.each_iterable(iterable) | ||
Creates an iterator for JavaScript async iterables. | ||
|
||
Example: | ||
```lua | ||
local async_iterator = js.each_iterable(some_js_async_iterable) | ||
for value in async_iterator do | ||
print(value) | ||
end | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
API docs for Lua's `os` module. | ||
|
||
## os.time(table?) | ||
Returns the current time when called without arguments, or a timestamp for a specific date when given a table. The table can contain the following fields: year (required), month (required), day (required), hour (defaults to 12), min (defaults to 0), and sec (defaults to 0). | ||
|
||
Example: | ||
```lua | ||
-- Get current timestamp | ||
print(os.time()) -- prints: current Unix timestamp | ||
|
||
-- Get timestamp for specific date | ||
local timestamp = os.time({ | ||
year = 2020, | ||
month = 1, | ||
day = 1 | ||
}) | ||
``` | ||
|
||
## os.date(format?, timestamp?) | ||
Returns a string or table containing date and time, formatted according to the given format string. If timestamp is not provided, formats the current time. | ||
|
||
Format specifiers: | ||
- `%Y`: Full year (e.g., "2024") | ||
- `%y`: Year without century (e.g., "24") | ||
- `%m`: Month (01-12) | ||
- `%b`: Abbreviated month name (e.g., "Jan") | ||
- `%B`: Full month name (e.g., "January") | ||
- `%d`: Day of month (01-31) | ||
- `%e`: Day of month (1-31) | ||
- `%H`: Hour (00-23) | ||
- `%I`: Hour (01-12) | ||
- `%M`: Minute (00-59) | ||
- `%S`: Second (00-59) | ||
- `%p`: AM/PM | ||
- `%A`: Full weekday name (e.g., "Sunday") | ||
- `%a`: Abbreviated weekday name (e.g., "Sun") | ||
- `%w`: Weekday (0-6, Sunday is 0) | ||
- `%j`: Day of year (001-366) | ||
- `%Z`: Time zone name | ||
- `%z`: Time zone offset from UTC | ||
- `%%`: Literal "%" | ||
|
||
Example: | ||
```lua | ||
-- Format specific date | ||
local date = os.date("%Y-%m-%d", os.time({ | ||
year = 2020, | ||
month = 1, | ||
day = 1 | ||
})) | ||
print(date) -- prints: 2020-01-01 | ||
|
||
-- Current date in different formats | ||
print(os.date("%Y-%m-%d")) -- prints: current date (e.g., "2024-03-14") | ||
print(os.date("%B %d, %Y")) -- prints: month day, year (e.g., "March 14, 2024") | ||
print(os.date("%I:%M %p")) -- prints: time in 12-hour format (e.g., "02:30 PM") | ||
print(os.date("%A, %B %d, %Y")) -- prints: full date (e.g., "Thursday, March 14, 2024") | ||
``` |
Oops, something went wrong.