[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: How two C-closures can share an upvalue??
- From: slonik.az@...
- Date: Sun, 13 Aug 2006 16:03:41 -0400
Hi Lua Experts,
Lua closures can share their private state with each other by sharing
their "outer local" variables. In the following code snippet "local
cnt" is accessible by both cnt_step() and cnt_get() and no other
function in the world could touch it.
function cnt_init()
local cnt= 0
function cnt_step() cnt= cnt + 1 end
function cnt_get() return cnt; end
end
cnt_init();
I would like to achieve the same effect using C-closures. But I cannot
figure out how?
Roberto's book "Programming in Lua, 2-nd edition" that I recently
bought shows how a C-closure stores its individual state in an upvalue
(lua_pushcclosure). But here I need two functions to have an access to
the same upvalue.
Any help is greatly appreciated.
Thanks and Best Regards,
--Leo--