This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
augustas656's profile picture

How is an file of functions converted to an API, what is an API?

Started by augustas656, 20 May 2014 - 06:07 PM
augustas656 #1
Posted 20 May 2014 - 08:07 PM
I know what an API is literally and what it does, how to use and make it. But, I know that an API is a table, now if I tried textutils.serialize(api), it would tell me that it can't serialize a type table. What is a type table, is it that an API is a metatable or what? Please explain, thnx.

Regards
Augustas
Edited on 20 May 2014 - 06:07 PM
apemanzilla #2
Posted 20 May 2014 - 08:12 PM
An API is a file with functions. It is converted to a table of functions that can be run when you load it with os.loadAPI. Does that answer the question?
augustas656 #3
Posted 20 May 2014 - 09:00 PM
Maybe.
What kind of table? A simple table with just functions? Oh, wait, that might of been the problem, I've loaded an API and then I went like api[1] instead of api[1](), wuold api[1]() work? If so, all is answered, if not, why so?

Regards,
Augustas
KingofGamesYami #4
Posted 20 May 2014 - 10:20 PM
The keys in the table are the function names:

os["pullEvent"] == os.pullEvent
os["pullEvent"]() == os.pullEvent()
Yevano #5
Posted 20 May 2014 - 10:28 PM
The keys in the table are the function names:

os["pullEvent"] == os.pullEvent
os["pullEvent"]() == os.pullEvent()

Not that it has anything to do with anything, but that second line will return false if you cause two different events to happen consecutively. :P/>
KingofGamesYami #6
Posted 20 May 2014 - 10:31 PM
The keys in the table are the function names:

os["pullEvent"] == os.pullEvent
os["pullEvent"]() == os.pullEvent()
Not that it has anything to do with anything, but that second line will return false if you cause two different events to happen consecutively. :P/>/>/>
well of course… I was saying they are equivalent, os.pullEvent() calls the same function as os["pullEvent"]()
Edited on 20 May 2014 - 08:31 PM
theoriginalbit #7
Posted 21 May 2014 - 02:27 AM
well of course… I was saying they are equivalent, os.pullEvent() calls the same function as os["pullEvent"]()
then use your words 'is equivalent to' 'cause I thought you were doing a comparison on it at first too.
augustas656 #8
Posted 21 May 2014 - 06:18 PM
Ok, I understand, thanks, I thought that an API was a regular table, so I've tested but forgot to do the (), so then I thought an API wasn't a regular table of functions, so I asked here for solely that purpose, and I've just realised my mistake. Thank you! :)/>
apemanzilla #9
Posted 21 May 2014 - 07:11 PM
Ok, I understand, thanks, I thought that an API was a regular table, so I've tested but forgot to do the (), so then I thought an API wasn't a regular table of functions, so I asked here for solely that purpose, and I've just realised my mistake. Thank you! :)/>/>
An API is a regular table. You can set custom keys in tables whenever you want.

local t = {}
t["a"] = function() print(5) end
t.a()
TheOddByte #10
Posted 21 May 2014 - 07:37 PM
As said above by people, it's a table with functions.

You could for example do this
API file

return{
	foo = function( text )
		print( text )
	end;

	test = function( text )
		print( #text )
	end;
}
Main file

local api = require( "<API file>" )
api.foo( "bar" )

Edit: Why are you trying to serialize an api? O_o
Edited on 21 May 2014 - 05:40 PM
theoriginalbit #11
Posted 22 May 2014 - 01:18 AM
As said above by people, it's a table with functions.

You could for example do this
API file

return{
	foo = function( text )
		print( text )
	end;

	test = function( text )
		print( #text )
	end;
}
Main file

local api = require( "<API file>" )
api.foo( "bar" )

Edit: Why are you trying to serialize an api? O_o
Hellkid, you should know by now that we don't have require in ComputerCraft, you should avoid confusing people with features we don't have…
augustas656 #12
Posted 22 May 2014 - 04:43 PM
Ok, I understand, thanks, I thought that an API was a regular table, so I've tested but forgot to do the (), so then I thought an API wasn't a regular table of functions, so I asked here for solely that purpose, and I've just realised my mistake. Thank you! :)/>/>
An API is a regular table. You can set custom keys in tables whenever you want.

local t = {}
t["a"] = function() print(5) end
t.a()

I never said an API wasn't a regular table. Where you quoted me I said that earlier I thought it wasn't, but know I know it is. Is it just me, or you don't get anything I write? No offense but it's just frustrating for me.
apemanzilla #13
Posted 22 May 2014 - 05:16 PM
Ok, I understand, thanks, I thought that an API was a regular table, so I've tested but forgot to do the (), so then I thought an API wasn't a regular table of functions, so I asked here for solely that purpose, and I've just realised my mistake. Thank you! :)/>/>/>/>
An API is a regular table. You can set custom keys in tables whenever you want.

local t = {}
t["a"] = function() print(5) end
t.a()

I never said an API wasn't a regular table. Where you quoted me I said that earlier I thought it wasn't, but know I know it is. Is it just me, or you don't get anything I write? No offense but it's just frustrating for me.
Sorry. It's easier to understand when proper grammar and spelling are used. I'm guessing English isn't your first language?
Edited on 22 May 2014 - 03:16 PM
TheOddByte #14
Posted 22 May 2014 - 07:56 PM
Hellkid, you should know by now that we don't have require in ComputerCraft, you should avoid confusing people with features we don't have…
Sorry.. I've gotten more used to LÖVE under the last month :P/>
augustas656 #15
Posted 23 May 2014 - 10:48 PM
Ok, I understand, thanks, I thought that an API was a regular table, so I've tested but forgot to do the (), so then I thought an API wasn't a regular table of functions, so I asked here for solely that purpose, and I've just realised my mistake. Thank you! :)/>/>/>/>
An API is a regular table. You can set custom keys in tables whenever you want.

local t = {}
t["a"] = function() print(5) end
t.a()

I never said an API wasn't a regular table. Where you quoted me I said that earlier I thought it wasn't, but know I know it is. Is it just me, or you don't get anything I write? No offense but it's just frustrating for me.
Sorry. It's easier to understand when proper grammar and spelling are used. I'm guessing English isn't your first language?

Most people that I talk to in most forums understand me or atleast give me the answers I'm looking for if I am looking for answers, it's because I read others' posts from various forums and try to speak in the same language, I try to use the local language. Word order and perhaps selection can be valid in varying forms, but can mean also a variety of different things. The word order and style of writing really depends on the person, and as I said again it can be valid but can also have many meanings. English isn't my first language but I know english better than my first language, and even though I still go to school, I am levelled more high the most other students at my school for a range of english literature, grammar, writing and reading skills. However, I really appreciate your effort in attempting to understand me and respond to my questions to help me with my computercraft scripting. :3

Regards
Augustas
Edited on 23 May 2014 - 08:49 PM