-
Notifications
You must be signed in to change notification settings - Fork 5
/
call.cpp
48 lines (43 loc) · 1.14 KB
/
call.cpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (c) 2000 Suneido Software Corp. All rights reserved
// Licensed under GPLv2
#include "call.h"
#include "interp.h"
#include "globals.h"
#include "sustring.h"
#include "ostreamstr.h"
#include "exceptimp.h"
// used by QueryParser for extend macros
// used by Query expressions FunCall
Value call(const char* fname, Lisp<Value> args) {
KEEPSP
int nargs = 0;
for (; !nil(args); ++args, ++nargs)
PUSH(*args);
return docall(globals[fname], CALL, nargs);
}
Value method_call(Value ob, const gcstring& method, Lisp<Value> args) {
KEEPSP
int nargs = 0;
for (; !nil(args); ++args, ++nargs)
PUSH(*args);
return docall(ob, new SuString(method), nargs);
}
// used by sunapp
const char* trycall(const char* fn, char* arg, int* plen) {
const char* str;
try {
Value result = call(fn, lisp(Value(new SuString(arg))));
gcstring gcstr = result.gcstr();
if (plen)
*plen = gcstr.size();
str = gcstr.str();
} catch (const Except& e) {
// TODO catch block return ?
OstreamStr oss;
oss << fn << "(" << arg << ") => " << e;
str = oss.str();
if (plen)
*plen = oss.size();
}
return str;
}