Another Lua class method

When I try to call a method of another class from another class, it says an error that

Attempt to call field 'LoadShift' (a nil value)

Here is my code, loginpage1.lua

local LoadShift = nil;
.
.
function LoadShift()

end

loginpage2.lua

local loginObj = require("com.classess.loginpage1")
loginObj.LoadShift();

What is the problem with my code, please help me solve this problem.

+4
source share
1 answer

Create your own class as follows

------------Your class LoadShift---------------
    local LoadShift = {}
    .
    .
    function LoadShift:LoadShiftFunc()
        --do somthing
    end
    .
    .
    return LoadShift
-------------------------------------

then require it and call this function, for example

---------------------

local LoadShift= require "LoadShift"
LoadShift:LoadShiftFunc()
+6
source

Source: https://habr.com/ru/post/1528926/


All Articles