This repository has been archived by the owner on Oct 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Tricks and tips
Martin Takáč edited this page Mar 14, 2021
·
1 revision
open import "prelude.ml"
let () =
put_line "Hello, world!"
open import "prelude.ml"
let () =
(put_line "Une")
(put_line "Deux")
(put_line "Trois")
unit
means that we will not return any value. _
indicates that we will not check the type of argument. The Amulet checks only the syntax of the lua code. Otherwise we can create anything there.
external val foo : _ -> unit =
"function(src) \
print(src) \
end"
external val string_extensions : {} -> unit =
"function(_) \
string.x_shift_path = function(path) \
local index = path:find('/') \
local curr = path \
local tail = nil \
if index then \
curr = path:sub(0, index - 1) \
tail = path:sub(index + 1) \
end \
return curr, tail \
end \
end"
external val x_first : string -> string =
"function(str) \
local curr, _ = str:x_shift_path() \
return cur \
end"
let () =
(string_extensions {})
put_line (x_first "path/to/anything")
type color =
| Red
| Orange
| Green
external val makeColor : string -> color =
"function(s) \
if s == 'red' then \
return {__tag = \"Red\"} \
end \
if s == 'orange' then \
return {__tag = \"Orange\"} \
end \
return {__tag = \"Green\"} \
end"
{{draft}}