Jump to content




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


  • You cannot reply to this topic
14 replies to this topic

#1 augustas656

  • Members
  • 158 posts

Posted 20 May 2014 - 07: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 by augustas656, 20 May 2014 - 07:07 PM.


#2 apemanzilla

  • Members
  • 1,421 posts

Posted 20 May 2014 - 07: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?

#3 augustas656

  • Members
  • 158 posts

Posted 20 May 2014 - 08: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

#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 20 May 2014 - 09:20 PM

The keys in the table are the function names:
os["pullEvent"] == os.pullEvent
os["pullEvent"]() == os.pullEvent()


#5 Yevano

  • Members
  • 376 posts
  • LocationUSA

Posted 20 May 2014 - 09:28 PM

View PostKingofGamesYami, on 20 May 2014 - 09:20 PM, said:

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

#6 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 20 May 2014 - 09:31 PM

View PostYevano, on 20 May 2014 - 09:28 PM, said:

View PostKingofGamesYami, on 20 May 2014 - 09:20 PM, said:

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 by KingofGamesYami, 20 May 2014 - 09:31 PM.


#7 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 21 May 2014 - 01:27 AM

View PostKingofGamesYami, on 20 May 2014 - 09:31 PM, said:

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.

#8 augustas656

  • Members
  • 158 posts

Posted 21 May 2014 - 05: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! :)

#9 apemanzilla

  • Members
  • 1,421 posts

Posted 21 May 2014 - 06:11 PM

View Postaugustas656, on 21 May 2014 - 05:18 PM, said:

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()


#10 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 21 May 2014 - 06: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 by TheOddByte, 21 May 2014 - 06:40 PM.


#11 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 22 May 2014 - 12:18 AM

View PostTheOddByte, on 21 May 2014 - 06:37 PM, said:

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...

#12 augustas656

  • Members
  • 158 posts

Posted 22 May 2014 - 03:43 PM

View Postapemanzilla, on 21 May 2014 - 06:11 PM, said:

View Postaugustas656, on 21 May 2014 - 05:18 PM, said:

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.

#13 apemanzilla

  • Members
  • 1,421 posts

Posted 22 May 2014 - 04:16 PM

View Postaugustas656, on 22 May 2014 - 03:43 PM, said:

View Postapemanzilla, on 21 May 2014 - 06:11 PM, said:

View Postaugustas656, on 21 May 2014 - 05:18 PM, said:

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 by apemanzilla, 22 May 2014 - 04:16 PM.


#14 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 22 May 2014 - 06:56 PM

View Posttheoriginalbit, on 22 May 2014 - 12:18 AM, said:

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

#15 augustas656

  • Members
  • 158 posts

Posted 23 May 2014 - 09:48 PM

View Postapemanzilla, on 22 May 2014 - 04:16 PM, said:

View Postaugustas656, on 22 May 2014 - 03:43 PM, said:

View Postapemanzilla, on 21 May 2014 - 06:11 PM, said:

View Postaugustas656, on 21 May 2014 - 05:18 PM, said:

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 by augustas656, 23 May 2014 - 09:49 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users