amber-lang / amber

💎 Amber the programming language compiled to Bash
https://amber-lang.com
GNU General Public License v3.0
3.93k stars 89 forks source link

[Questions] Export function to be used by other bash script #598

Closed ArnaudG-Eyesoft closed 2 hours ago

ArnaudG-Eyesoft commented 4 hours ago

Hello,

I am trying to use Amber with my current toolset, without migrating everything at once, and one tool I use (mo) needs to have access to specifically named function in my script.

Here is simple version of what I am trying to achieve using Amber:

#!/usr/bin/env bash

source ./mo

DEMO() {
  echo "Test"
}

echo "{{DEMO}}" | mo

# Output: "Test"

If I declare an Amber function that is not used -> it will not be compiled to bash. If I use the function to "force" load it -> the function name will be changed.

In your opinion, what's the best way to achieve that? Maybe a specific compiler flag can be used to avoid that? Or should I write a custom Amber based template engine for my use case instead of using mo?

Thanks!

Mte90 commented 2 hours ago

We have a ticket about to generate functions and variables in bash that can be reused outside (I can't find it now). Right now it is something you can do as in compilation the function/variable names changes.

ArnaudG-Eyesoft commented 2 hours ago

Found it! Thanks

Closing as duplicate of #253