Skip to content

Commit

Permalink
_G access limit.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdzl2003 committed Feb 17, 2013
1 parent 4a92d20 commit f5703d4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion node/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -295,5 +295,5 @@ function Buffer.isBuffer(buf)
return ffi.istype(bufferCT, buf)
end

_G.Buffer = Buffer
rawset(_G, "Buffer", Buffer)
return Buffer
9 changes: 9 additions & 0 deletions node/lua_ex.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,12 @@ function newWholeWeakTable()
return ret
end


-- limit global newindex
-- only rawset(_G, key, value) is allowed.
setmetatable(_G, {
__newindex = function (t, k, v)
print("Warning: writing global variant "..k)
rawset(t, k, v)
end
})
4 changes: 4 additions & 0 deletions node/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ end

local path = require("path")

require("lua_ex")

-- TODO: use option module to parse command line.
dofile(arg[1])

local uv = require("uv")
uv.uv_run(uv.uv_default_loop(), uv.UV_RUN_DEFAULT)
2 changes: 1 addition & 1 deletion node/path.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
-- read LICENSE.md for more informations.

local path = {}
_G.path = path
rawset(_G, "path", path)

local curdir = "."
local pardir = ".."
Expand Down
14 changes: 13 additions & 1 deletion test/uv/testuv.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
local uv = require("uv")
local ffi = require("ffi")

uv.uv_run(uv.uv_default_loop(), uv.UV_RUN_DEFAULT)
local idler = ffi.new("uv_idle_t[1]");

uv.uv_idle_init(uv.uv_default_loop(), idler);

local counter = 0
uv.uv_idle_start(idler, function(handle)
counter = counter + 1
if (counter > 10e6) then
uv.uv_idle_stop(handle)
print("Exiting... ")
end
end);

0 comments on commit f5703d4

Please sign in to comment.