Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vsky committed Jun 21, 2020
1 parent 88f937a commit 9decd7e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
21 changes: 8 additions & 13 deletions lua_examples/lfs/_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
module related initialisaion in this. This example uses standard Lua features to
simplify the LFS API.
For Lua 5.1, the first section adds a 'LFS' table to _G and uses the __index
metamethod to resolve functions in the LFS, so you can execute the main
For Lua 5.1, the first section adds a 'LFS' table to _G and uses the __index
metamethod to resolve functions in the LFS, so you can execute the main
function of module 'fred' by executing LFS.fred(params), etc.
It also implements some standard readonly properties:
Expand All @@ -24,13 +24,13 @@
print(table.concat(LFS._list,'\n'))
gives you a single column listing of all modules in the LFS.
For Lua 5.3 LFS table is already populated by the firmware itself so this part of the
code is skipped.
For Lua 5.3 LFS table is populated by the LFS implementation in C so this part
of the code is skipped.
---------------------------------------------------------------------------------]]

local index = node.flashindex
local G=_ENV or getfenv()
if _VERSION == 'Lua 5.1' then
local index = node.flashindex
if _VERSION == 'Lua 5.1' then
local lfs_t = {
__index = function(_, name)
local fn_ut, ba, ma, size, modules = index(name)
Expand All @@ -54,12 +54,7 @@ if _VERSION == 'Lua 5.1' then
end,
}

G.LFS = setmetatable(lfs_t,lfs_t)
--[[-------------------------------------------------------------------------------
You can add any other initialisation here, for example a couple of the globals
are never used, so setting them to nil saves a couple of global entries
---------------------------------------------------------------------------------]]

G.LFS = setmetatable(lfs_t,lfs_t)
G.module = nil -- disable Lua 5.0 style modules to save RAM
package.seeall = nil
end
Expand Down Expand Up @@ -96,4 +91,4 @@ G.dofile = function(n)
local mod, ext = n:match("(.*)%.(l[uc]a?)");
local fn, ba = index(mod)
if ba or (ext ~= 'lc' and ext ~= 'lua') then return df(n) else return fn() end
end
end
4 changes: 3 additions & 1 deletion tools/luacheck_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,9 @@ stds.nodemcu_libs = {
pack = empty,
unpack = empty,
size = empty,
package = {fields = {seeall = read_write}}
package = {fields = {seeall = read_write}},
_ENV = empty,
LFS = {read_only = true, other_fields = true}
}
}

Expand Down

0 comments on commit 9decd7e

Please sign in to comment.