about summary refs log tree commit diff stats
path: root/wiki/vendor/splitbrain/php-cli/src/Exception.php
blob: b2aa98115e7bd1f29acb92210d3450e8a5596237 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php

namespace splitbrain\phpcli;

/**
 * Class Exception
 *
 * The code is used as exit code for the CLI tool. This should probably be extended. Many cases just fall back to the
 * E_ANY code.
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 * @license MIT
 */
class Exception extends \Exception
{
    const E_ANY = -1; // no error code specified
    const E_UNKNOWN_OPT = 1; //Unrecognized option
    const E_OPT_ARG_REQUIRED = 2; //Option requires argument
    const E_OPT_ARG_DENIED = 3; //Option not allowed argument
    const E_OPT_ABIGUOUS = 4; //Option abiguous
    const E_ARG_READ = 5; //Could not read argv

    /**
     * @param string $message The Exception message to throw.
     * @param int $code The Exception code
     * @param \Exception $previous The previous exception used for the exception chaining.
     */
    public function __construct($message = "", $code = 0, \Exception $previous = null)
    {
        if (!$code) {
            $code = self::E_ANY;
        }
        parent::__construct($message, $code, $previous);
    }
}
>std / "core"]) proc main() = let i = initInterpreter("myscript.nim") i.implementRoutine("*", "exposed", "addFloats", proc (a: VmArgs) = setResult(a, getFloat(a, 0) + getFloat(a, 1) + getFloat(a, 2)) ) i.evalScript() let foreignProc = i.selectRoutine("hostProgramRunsThis") if foreignProc == nil: quit "script does not export a proc of the name: 'hostProgramRunsThis'" let res = i.callRoutine(foreignProc, [newFloatNode(nkFloatLit, 0.9), newFloatNode(nkFloatLit, 0.1)]) doAssert res.kind == nkFloatLit echo res.floatVal let foreignValue = i.selectUniqueSymbol("hostProgramWantsThis") if foreignValue == nil: quit "script does not export a global of the name: hostProgramWantsThis" let val = i.getGlobalValue(foreignValue) doAssert val.kind in {nkStrLit..nkTripleStrLit} echo val.strVal i.destroyInterpreter() main() block issue9180: proc evalString(code: string, moduleName = "script.nim") = let stream = llStreamOpen(code) let std = findNimStdLibCompileTime() var intr = createInterpreter(moduleName, [std, std / "pure", std / "core"]) intr.evalScript(stream) destroyInterpreter(intr) llStreamClose(stream) evalString("echo 10+1") evalString("echo 10+2") block error_hook: type VMQuit = object of CatchableError let i = initInterpreter("invalid.nim") i.registerErrorHook proc(config: ConfigRef; info: TLineInfo; msg: string; severity: Severity) {.gcsafe.} = if severity == Error and config.errorCounter >= config.errorMax: echo "raising VMQuit" raise newException(VMQuit, "Script error") doAssertRaises(VMQuit): i.evalScript()