-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathluaCBLang.cpp
More file actions
118 lines (87 loc) · 2.5 KB
/
luaCBLang.cpp
File metadata and controls
118 lines (87 loc) · 2.5 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Author: Greg "fugue" Santucci, 2011
// Email: thecodewitch@gmail.com
// Web: http://createuniverses.blogspot.com/
#include "luaCB.h"
int luaCBLisp(lua_State * L)
{
#ifdef __PRAXIS_WITH_LISP__
int n = lua_gettop(L);
if(n!=1) luaL_error(L, "1 argument expected.");
std::string sCode = luaL_checkstring(L, 1);
lispCall(sCode);
std::string sOut = lispGetOutput();
std::string sErr = lispGetError();
if(sErr != "")
sOut = sOut + std::string(" ") + sErr;
lua_pushstring(L, sOut.c_str());
return 1;
#else
lua_pushstring(L, "Lisp not compiled.");
return 1;
#endif
}
int luaCBForth(lua_State * L)
{
#ifdef __PRAXIS_WITH_FORTH__
int n = lua_gettop(L);
if(n!=1) luaL_error(L, "1 argument expected.");
std::string sCode = luaL_checkstring(L, 1);
forthCall(sCode);
std::string sOut = forthGetOutput();
std::string sErr = forthGetError();
if(sErr != "")
sOut = sOut + std::string(" ") + sErr;
lua_pushstring(L, sOut.c_str());
return 1;
#else
lua_pushstring(L, "Forth not compiled.");
return 1;
#endif
}
int luaCBIoLang(lua_State * L)
{
#ifdef __PRAXIS_WITH_IO__
int n = lua_gettop(L);
if(n!=1) luaL_error(L, "1 argument expected.");
std::string sCode = luaL_checkstring(L, 1);
ioCallWithReply(sCode);
lua_pushstring(L, ioGetReply().c_str());
lua_pushstring(L, ioGetTrace().c_str());
return 2;
#else
lua_pushstring(L, "Io not compiled.");
lua_pushstring(L, "");
return 2;
#endif
}
int luaCBSetLispTraceVerbosity(lua_State * L)
{
#ifdef __PRAXIS_WITH_LISP__
extern int g_nLispTraceVerbosity;
int n = lua_gettop(L);
if(n!=1) luaL_error(L, "1 argument expected.");
int nVerbosity = luaL_checknumber(L, 1);
g_nLispTraceVerbosity = nVerbosity;
#endif
return 0;
}
int luaCBGetLispTraceVerbosity(lua_State * L)
{
#ifdef __PRAXIS_WITH_LISP__
extern int g_nLispTraceVerbosity;
// int n = lua_gettop(L);
// if(n!=1) luaL_error(L, "1 argument expected.");
lua_pushnumber(L, g_nLispTraceVerbosity);
#else
lua_pushnumber(L, 0);
#endif
return 1;
}
void luaInitCallbacksLang()
{
lua_register(g_pLuaState, "lisp", luaCBLisp);
lua_register(g_pLuaState, "forth", luaCBForth);
lua_register(g_pLuaState, "iolang", luaCBIoLang);
lua_register(g_pLuaState, "setLispTraceVerbosity", luaCBSetLispTraceVerbosity);
lua_register(g_pLuaState, "getLispTraceVerbosity", luaCBGetLispTraceVerbosity);
}