2014-02-26 50 views
4

当我尝试调用其他类的方法从另一个类,它说错误消息,另一类的方法调用的Lua

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

这里是我的代码, loginpage1.lua

local LoadShift = nil; 
. 
. 
function LoadShift() 

end 

loginpage2。 lua

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

我的代码有什么问题,请帮我解决这个问题

回答

6

作出这样

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

那么你的自定义类需要它,并呼吁像

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

local LoadShift= require "LoadShift" 
LoadShift:LoadShiftFunc() 
+0

我这样做的功能,它doessnt工作 – Fazil

+0

@Fazil:检查您的LUA类的拼写和大小写。它是否被命名为'LoadShift.lua'..?然后只有上面的代码将工作... –

+0

我没有拼写错误 – Fazil