aboutsummaryrefslogtreecommitdiff
path: root/src/functionopen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/functionopen.cpp')
-rw-r--r--src/functionopen.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/functionopen.cpp b/src/functionopen.cpp
new file mode 100644
index 0000000..4026a8c
--- /dev/null
+++ b/src/functionopen.cpp
@@ -0,0 +1,42 @@
1#include "functionopen.h"
2#include "filemgr.h"
3
4#include <bu/plugger.h>
5PluginInterface3( pluginFunctionOpen, open, FunctionOpen, Function,
6 "Mike Buland", 0, 1 );
7
8FunctionOpen::FunctionOpen()
9{
10}
11
12FunctionOpen::~FunctionOpen()
13{
14}
15
16Bu::String FunctionOpen::getName() const
17{
18 return "open";
19}
20
21Variable FunctionOpen::call( Variable &input, VarList lParams )
22{
23 if( lParams.getSize() != 2 )
24 {
25 throw Bu::ExceptionBase(
26 "open takes two parameters, filename and mode."
27 );
28 }
29 Bu::String sMode = lParams.last().toString().toLower();
30 int iMode = Bu::File::Create;
31 if( sMode.find('w') )
32 iMode |= Bu::File::Write;
33 if( sMode.find('r') )
34 iMode |= Bu::File::Read;
35 Variable vRet(
36 (void *)FileMgr::getInstance().open(
37 lParams.first().toString(), iMode
38 )
39 );
40 return vRet;
41}
42