Git commit ID added to stamp

Fixes #2921: getValue() now also returns pilot position
Fixes #3062: Close any Lua open files when radio powers off
Fixes #3095: Lua string library added (only 6k bytes of flash used)
Re #3095: luaGetVersion() also returns version as numbers
(Ported from master 7ef790d3..4d0bd14ad and squashed into one commit)
This commit is contained in:
Damjan Adamic
2015-11-25 18:00:44 +01:00
parent 7e6dc610ac
commit 7538fcfb51
11 changed files with 87 additions and 41 deletions
+1
View File
@@ -28,6 +28,7 @@ extern const luaL_Reg baselib[];
extern const luaL_Reg mathlib[];
extern const luaL_Reg bitlib[];
extern const luaL_Reg iolib[];
extern const luaL_Reg strlib[];
extern const luaL_Reg opentxLib[];
extern const luaL_Reg lcdLib[];
+1
View File
@@ -46,6 +46,7 @@ const luaR_table lua_rotable[] =
{LUA_MATHLIBNAME, mathlib, mathlib_vals},
{LUA_BITLIBNAME, bitlib, NULL},
{LUA_IOLIBNAME, iolib, NULL},
{LUA_STRLIBNAME, strlib, NULL},
{"lcd", lcdLib, NULL},
{"model", modelLib, NULL},
{"__baselib", baselib, NULL},
+13 -16
View File
@@ -203,16 +203,17 @@ static int io_close (lua_State *L) {
#endif
}
#if !defined(USE_FATFS)
static int f_gc (lua_State *L) {
#if !defined(USE_FATFS)
LStream *p = tolstream(L);
if (!isclosed(p) && p->f != NULL)
aux_close(L); /* ignore closed and incompletely open files */
#endif
f_close(tofile(L)); // no need to check if file was already closed (fatfs will not close it if p->f->fs is 0)
return 0;
}
#if !defined(USE_FATFS)
/*
** function to close regular files
*/
@@ -659,31 +660,27 @@ const luaL_Reg iolib[] = {
{NULL, NULL}
};
#if !defined(USE_FATFS)
/*
** methods for file handles
*/
static const luaL_Reg flib[] = {
{"close", io_close},
{"flush", f_flush},
{"lines", f_lines},
{"read", io_read},
{"seek", f_seek},
{"setvbuf", f_setvbuf},
{"write", f_write},
{"__gc", f_gc},
{"__tostring", f_tostring},
// {"close", io_close},
// {"flush", f_flush},
// {"lines", f_lines},
// {"read", io_read},
// {"seek", f_seek},
// {"setvbuf", f_setvbuf},
// {"write", f_write},
{"__gc", f_gc}, // we define only garbage collector to close any leftover open files
// {"__tostring", f_tostring},
{NULL, NULL}
};
#endif
static void createmeta (lua_State *L) {
luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */
lua_pushvalue(L, -1); /* push metatable */
// lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */
// luaL_setfuncs(L, flib, 0); /* add file methods to new metatable */
lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */
luaL_setfuncs(L, flib, 0); /* add file methods to new metatable */
lua_pop(L, 1); /* pop new metatable */
}
+4 -3
View File
@@ -9,6 +9,7 @@
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define lstrlib_c
@@ -975,7 +976,7 @@ static int str_format (lua_State *L) {
/* }====================================================== */
static const luaL_Reg strlib[] = {
const luaL_Reg strlib[] = {
{"byte", str_byte},
{"char", str_char},
{"dump", str_dump},
@@ -993,7 +994,7 @@ static const luaL_Reg strlib[] = {
{NULL, NULL}
};
#if 0
static void createmetatable (lua_State *L) {
lua_createtable(L, 0, 1); /* table to be metatable for strings */
lua_pushliteral(L, ""); /* dummy string */
@@ -1014,4 +1015,4 @@ LUAMOD_API int luaopen_string (lua_State *L) {
createmetatable(L);
return 1;
}
#endif