Skip to content

Instantly share code, notes, and snippets.

@blam23
Created September 15, 2012 23:38
Show Gist options
  • Save blam23/3730360 to your computer and use it in GitHub Desktop.
Save blam23/3730360 to your computer and use it in GitHub Desktop.
axScript3 REPL
//REPL Script 1.1
#module <Ax/STD.dll> // Needed for console output
#module <Ax/Exit.dll> // Needed for exit hook
// Exit Handler function.
// Whenever the script is stopped this function is called.
// It can be used to catch errors and continue the script.
~(exit: type error |
(
~[ExitPoint]
(set ^err error)
// All the reflection causes exceptions to go a bit crazy.
// So we loop through all the inner exceptions to find
// the root cause of the error.
(while %{neq err.InnerException null} {
(set ^err err.InnerException)
})
(ifelse (eq type #EXITCODE_ERROR) {
(printl "# {0}\n\n" err.Message)
(return false) // Returning false means it keeps running
} {
// Clean exit, no need to return anything.
(printl "Goodbye.")
})
)
)
// Where our script starts.
// Sets up the title and begins the loop.
~(main: args |
(
~[EntryPoint]
(consoletitle "axScript REPL 1.1")
(loop)
)
)
// Our Read Eval Print Loop!
// Exits on blank lines
~(loop:
(
(set ^quit false)
(do {
(print "> ")
(set ^inp (read))
(ifelse (eq inp.Length 0) {
(set ^quit true)
} {
//REPL Script 1.1
#module <Ax/STD.dll> // Needed for console output
#module <Ax/Exit.dll> // Needed for exit hook
// Exit Handler function.
// Whenever the script is stopped this function is called.
// It can be used to catch errors and continue the script.
~(exit: type error |
(
~[ExitPoint]
(set ^err error)
// All the reflection causes exceptions to go a bit crazy.
// So we loop through all the inner exceptions to find
// the root cause of the error.
(while %{neq err.InnerException null} {
(set ^err err.InnerException)
})
(ifelse (eq type #EXITCODE_ERROR) {
(printl "# {0}\n\n" err.Message)
(return false) // Returning false means it keeps running
} {
// Clean exit, no need to return anything.
(printl "Goodbye.")
})
)
)
// Where our script starts.
// Sets up the title and begins the loop.
~(main: args |
(
~[EntryPoint]
(consoletitle "axScript REPL 1.1")
(loop)
)
)
// Our Read Eval Print Loop!
// Exits on blank lines
~(loop:
(
(set ^quit false)
(do {
(print "> ")
(set ^inp (read))
(ifelse (eq inp.Length 0) {
(set ^quit true)
} {
(printl "{0}" (run inp))
})
} %{eq quit false})
)
)
})
} %{eq quit false})
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment