Amber icon indicating copy to clipboard operation
Amber copied to clipboard

✨ [Feature request] allow export amber function as bash function

Open woodgear opened this issue 1 year ago • 2 comments

since that we could source this compiled bash script and call amber function in bash script or shell. and has a way to enhance/replace old bash script.

woodgear avatar May 22 '24 16:05 woodgear

do you want something like this?

export pub fun say_hi() {
    echo "hi!"
}

to compile into

say_hi() { # name preserved
    echo "hi!"
}
export -f say_hi

b1ek avatar May 26 '24 11:05 b1ek

@b1ek We could unify this with the proposed syntax in this issue https://github.com/Ph0enixKM/Amber/issues/68 with export

export pub fun foo() {
    echo "Hello"
}

export FOO = "Env variable"

bash:

# Amber function accessible from Amber itself
_AF_foo_v0() {
    echo "Hello"
}

# Renamed Amber function for export
foo() {
  # Call the Amber function
  _AF_foo_v0 "$@"
  # Echo the result that it returns
  echo "${_AF_foo_v0__0}"
  # Return the same exit code (if not failable - return 0)
  return 0
}

# Export the function with the name
export -f foo

# Export the environment variable
export FOO="Env variable"

Ph0enixKM avatar May 27 '24 09:05 Ph0enixKM

Closing as duplicate of https://github.com/amber-lang/amber/issues/253

Mte90 avatar Jul 19 '24 09:07 Mte90