Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Calling a function on a table, and how does this code work?

Asked by 8 years ago
01function module:GetDatabase(sheet)
02    local database = {}
03    function database:PostAsync(key, value)
04        return doPost(sheet, key, value)
05    end
06    function database:GetAsync(key)
07        return doGet(sheet, key)
08    end
09    return database
10end

So, from my understanding, whenever PostAsync() is called, doPost is returned, and whenever GetAsync() is called, doGet is returned? Am I correct in this understanding?

Also, functions are being called on the table? This code is confusing me for some reason.

0
To clarify: this is someone else's code that I'm trying to learn from. I'm sure you figured that out, though. fireflame09225 11 — 8y

1 answer

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
8 years ago

Whenever you call :PostAsync() on the module, which is what the script is in, it'll return a function doPost() that I'm assuming uses PostAsync. This looks like code for a Sheets API.

0
I've been using and learning from his source code and trying to make it into an idea I've had for a while. Kinda excited about this project. fireflame09225 11 — 8y
Ad

Answer this question