Comments (5)
Hi, Martin,
Actually, that works fine if you do this:
function Actor:__init()
Actor.super.__init(self)
self.test2 = "2"
for k, v in pairs( self ) do
print( k .. ": " .. v .. "\n" )
end
end
Take a look at this section in the Readme: Chained initialisation
Best regards
Roland.
from 30log.
I modified the code but I still have the same error:
class = require "vendors.30log.30log"
Card = class { __name = "Card" }
function Card:__init()
self.test1 = "1"
end
Actor = Card:extends { __name = "Actor" }
function Actor:__init()
Actor.super.__init()
self.test2 = "2"
for k, v in pairs( self ) do
print( k .. ": " .. v .. "\n" )
end
end
test = Actor()
And result is:
lua: test.lua:6: attempt to index local 'self' (a nil value)
stack traceback:
test.lua:6: in function '__init'
test.lua:12: in function '__init'
./vendors/30log/30log.lua:35: in function <./vendors/30log/30log.lua:32>
(tail call): ?
test.lua:19: in main chunk
[C]: ?
For information I'm running Lua 5.1.4
from 30log.
Sorry Martin, my bad, I didn't give the correct code.
See the previous sample I gave, I just updated it.
As a matter of fact, you when you can to write a class constructor and you need to call its super class constructor, you will have to call explicitely the superclass itself, passing it the object to be instantiated.
function Subclass:__init(...)
Superclass.super.__init(self)
-- ... rest of the code
end
Sorry for the inconvenience.
Best regards,
Roland.
from 30log.
OK, thank you very much. It works now :)
from 30log.
Awesome. Thanks.
from 30log.
Related Issues (20)
- Inheritance and super
- Inheritance and super HOT 2
- Singleton version HOT 1
- Missing comma HOT 1
- Need help on using new() HOT 7
- No easy way to clone classes. HOT 5
- Double class inheritence super
- isClass return false when using multiple 30log instances HOT 1
- the table is not copy~ HOT 1
- the table is not copy~~ HOT 5
- Stack overflow when adding static instance. HOT 2
- Subclasses retain old members after changes to superclass
- way to enumerate all + set/get properties
- Subclasse "capture" super's __subclasses entry
- the "1log"
- Troublesome deep-copy on object instantiation
- test('__ipairs is supported') are unassertive on travis's Lua 5.3 environment HOT 2
- class._VERSION = '30log v1.2.0'
- Mixin is not working when :new method is present HOT 1
- Unused code "c.__instances"
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 30log.