Comments (4)
Hope, problem solved, if not feel free to open another issue
from effil.
If instead of _timersContainerClass
I use everywhere, including in the class definition, effil.G._timersContainerClass
, everything seems to be working:
Class:
effil = require('effil')
effil.G._timersContainerClass = effil.table()
-- Metamethods
function effil.G._timersContainerClass:__index(key)
local value = effil.rawget(self, key) -- workaround for effil __index problem in this effil 0.1.0, see #139
if value ~= nil then
return value
end
return effil.G._timersContainerClass[key]
end
-- Object creation method.
function effil.G._timersContainerClass:new()
local outer = effil.table()
effil.setmetatable(outer, self)
return outer
end
function effil.G._timersContainerClass:getParent()
return tostring(effil.G._timersContainerClass)
end
Code:
effil = require('effil')
pl = effil.table()
require('timersTEST2')
t = effil.G._timersContainerClass:new()
function checkExpired(t)
effil = require "effil" -- MUST be global (?)
print('INSIDE CLASS', effil.G._timersContainerClass) -- OK, xyz as outside
print('INSIDE PARENT1', effil.G._timersContainerClass:getParent()) -- OK, xyz
print('INSIDE PARENT2', t:getParent()) -- OK, xyz
end
print('OUTSIDE CLASS', effil.G._timersContainerClass) -- OK, xyz
print('OUTSIDE PARENT1', effil.G._timersContainerClass:getParent()) -- OK, xyz
print('OUTSIDE PARENT2', t:getParent()) -- OK, xyz
effil.sleep(1, 's')
thread = effil.thread(checkExpired)(t)
effil.sleep(1, 's')
thread:status() -- Shows where it failed: in __index while trying t:getParent()
But this is not what I want, since I cannot use effil.G
to export the class.
I do not want to export every class I use to every thread I defined, since there are many.
from effil.
Hello, adrfantini!
The problem caused by _G
in your function's upvalue again.
You have declared your class global variable:
_timersContainerClass = effil.table()
And after that references it in function:
function _timersContainerClass:getParent()
return tostring(_timersContainerClass)
end
So, _timersContainerClass:getParent
has _G
in it's upvalues. But it does not work in Lua, docs here.
To fix the problem you should declare it as a local variable
local _timersContainerClass = effil.table()
.
And it's better always (where it's possible) do that.
After that you can expose _timersContainerClass
like that:
_timersContainerClass = require 'timers'
- preferable way (make return _timersContainerClass
in your timers module)
Or like that:
_G._timersContainerClass = _timersContainerClass
- at the end of 'timers' module. Not really cool, but still works
from effil.
Once again, thank you very much for the time you've taken to dispel my doubts. It's quite clear now!
from effil.
Related Issues (20)
- Best way to export Effil itself to threads? HOT 12
- effil.version is 0.1.0 HOT 5
- Compilation errors when upgrading HOT 3
- Which is more efficient, channels or tables? HOT 7
- Support for <luav5.3.6?
- Shouldn't link to LUA_LIBRARY on Linux HOT 1
- add effil.is_canceled() method HOT 1
- Issue assigning effil threads to effil table classes: Unable to dump Lua function HOT 4
- Why are some local functions dumpable to effil.table, and some not? How to tell one from the other? HOT 3
- Does effil support iOS and Android? HOT 1
- Sol2 version dependency HOT 1
- Effil fails serialisation of functions with custom environment HOT 6
- Concurrency issues with parallel threads: unavoidable? HOT 2
- [Request] Add some callback. HOT 9
- Trying to build for Windows produces an error, any idea what it is? HOT 1
- .
- Lua 5.4 support ? HOT 2
- Add peek method to channels
- Compilation issue with Sol. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from effil.