Strange behavior in function parameters

For some reason, my function always thinks the first parameter is a Table.

The file is functions.lua

local M = {}  
local testfunction = function(param1, param2)  
 print ("param1", param1)  
 print ("param2", param2)  
end  
M.testfunction = testfunction  
return M  

But then to use this, I have to do the following:

local funcs = require "functions"  
...  
funcs:testfunction("test 1", "test 2")  
--[[  
Output is:  
param1 table0FF34  
param2 test 1  
]]--  

OK, so I can actually do the following HACK to get it to work:

local M = {}  
local testfunction = function(param1, param2, param3)  
 print ("param2", param2)  
 print ("param3", param3)  
end  
M.testfunction = testfunction  
return M  

Then:

local funcs = require "functions"  
...  
funcs:testfunction("test 1", "test 2")  
--[[  
Output is:  
param2 test 1  
param3 test 2  
]]--  

Is this supposed to happen? Is this a bug? Do I not know something about LUA or Corona that I should that is causing this?

Please help, I’d hate to continue forward with a weird hack in my code :slight_smile: [import]uid: 85633 topic_id: 14809 reply_id: 314809[/import]

Quite simple explanation… you will laugh at the end of it

do you know why in LUA we have two ways of calling a function?

object.function()

and

object:function()

so when we call the object:function( param1, param2) , we are basically calling it as

object.function ( object, param1, param2 )

whereas when we call object.function (param1, param2) it is being called as object.function (param1, param2)

so in your case, just call it as local funcs = require "functions" ... funcs.testfunction("test 1", "test 2")
instead of calling it as you are

local funcs = require "functions" ... funcs:testfunction("test 1", "test 2")

The strange behaviour is *intended* the way lua works… :wink:

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 14809 reply_id: 54789[/import]

That’s it… THANK YOU!

I actually remember reading about that from when I was just getting started with LUA a couple days ago.

It’s not all sticking yet. Thank you again for your help. [import]uid: 85633 topic_id: 14809 reply_id: 54795[/import]