Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2838d60

Browse files
Update LuaWrapper.cpp
Added import for lua standard libraries: - base (tostring(), `tonumber(), etc.) - math - table (insert(), sort(), remove(), ...) - string (len(), match(), ...) Replaced print() function with the original version modified with Serial
1 parent 39b1295 commit 2838d60

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎src/LuaWrapper.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
11
#include "LuaWrapper.h"
22

3+
extern "C" {
4+
static int lua_wrapper_print (lua_State *L) {
5+
int n = lua_gettop(L); /* number of arguments */
6+
int i;
7+
lua_getglobal(L, "tostring");
8+
for (i=1; i<=n; i++) {
9+
const char *s;
10+
size_t l;
11+
lua_pushvalue(L, -1); /* function to be called */
12+
lua_pushvalue(L, i); /* value to print */
13+
lua_call(L, 1, 1);
14+
s = lua_tolstring(L, -1, &l); /* get result */
15+
if (s == NULL)
16+
return luaL_error(L, "'tostring' must return a string to 'print'");
17+
if (i>1) Serial.write("\t");
18+
Serial.write(s);
19+
lua_pop(L, 1); /* pop result */
20+
}
21+
Serial.println();
22+
return 0;
23+
}
24+
}
25+
326
LuaWrapper::LuaWrapper() {
427
_state = luaL_newstate();
28+
luaopen_base(_state);
29+
luaopen_table(_state);
30+
luaopen_string(_state);
31+
luaopen_math(_state);
32+
lua_register(_state, "print", lua_wrapper_print);
533
}
634

735
String LuaWrapper::Lua_dostring(const String *script) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /