Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lua] Modules are not initialized in derived classes when the module is used in the base class #1052

Open
jlfarris91 opened this issue Mar 22, 2022 · 1 comment

Comments

@jlfarris91
Copy link

It looks like modules are not correctly initialized for derived classes where the module is used in the base class.

I have a base class TlsBuildingDefinition that uses a module called UnitDefinitionInitModule and a derived class called CannonTowerDefinition.

image

image

In the compiled lua you can see that the TlsBuildingDefinition create function initializes all the module fields, but the CannonTowerDefinition create function does not.

image

image

So, when constructing CannonTowerDefinition instance, all the module fields are nil and ultimately break a lot of dependent code.

@Frotty
Copy link
Member

Frotty commented Jan 14, 2024

Module init should only be for the class that uses it. If it's not inited for you then the issue in your case is not missing module init, but The CannonTower constructor not calling the super constructor and thus the module init correctly.
In your example the important code should be in the CannonTowerDefinition_construct_CannonTowerDefinition function, which you did not include.
I tried to reproduce this with a small example:

module M
    protected var mi = 1

interface I

class A
    var ai = 2

    use M

class B extends A implements I
    var bi = 3

class C extends B
    var ci = 4

init
    doAfter(0.7) ->
        let c = new C()
        print("b test")
        print(c.mi)
        print(c.ai)
        print(c.bi)
        print(c.ci)

But this works fine, the super constructor call is added.
@jlfarris91 If you still have this issue please post a complete, reproducible example.

Perhaps the issue in your case is simply trying to access the module's values, before they are inited?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants