-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.cpp
83 lines (76 loc) · 1.94 KB
/
functions.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
////////////////////////////////////////////////////////////////////////////////
// DScript Scripting Language
// Copyright (C) 2003 Bryan "daerid" Ross
//
// Permission to copy, use, modify, sell and distribute this software is
// granted provided this copyright notice appears in all copies. This
// software is provided "as is" without express or implied warranty, and
// with no claim as to its suitability for any purpose.
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// DScript Headers
#include "functions.h"
////////////////////////////////////////////////////////////////////////////////
using namespace std;
using namespace dscript;
func_table::entry* func_table::find(string_table::entry name)
{
func_map::iterator found = functions.find(name);
if(found == functions.end())
return 0;
else
return &(found->second);
}
void func_table::add_script_func
(
string_table::entry name,
instr_iter begin,
instr_iter start,
instr_iter end
)
{
entry& e = functions[name];
e.begin = begin;
e.start = start;
e.end = end;
e.is_host = false;
e.name = name;
}
void func_table::add_host_func
(
string_table::entry name,
host_function_t callback
)
{
add_host_func(name,callback,-1,-1,"");
}
void func_table::add_host_func
(
string_table::entry name,
host_function_t callback,
int minargs,
int maxargs,
const char* usage
)
{
entry& e = functions[name];
e.is_host = true;
e.name = name;
e.host_func = callback;
e.min_args = minargs;
e.max_args = maxargs;
if(usage != 0)
e.usage_string = usage;
}
void func_table::remove_host_func(
string_table::entry name
)
{
// ok, find it
func_map::iterator f = functions.find(name);
if(f != functions.end())
{
if(f->second.is_host)
functions.erase(f);
}
}