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

Create table (which can be used in code) from API/file

Started by oeed, 18 July 2014 - 05:28 AM
oeed #1
Posted 18 July 2014 - 07:28 AM
I'm working on releasing Bedrock at the moment and one of the things I'm trying to do is put the APIs in table form in the one file. So, essentially there are about 15 or so other files which I'd like to keep separate in development (to keep the code clean), however, when I run a file it will copy the base API and all the other API files in to one file when it's ready for release. The easiest (that I can think of) way to do this is to simply have each API as a table in the final file.

So essentially, I'd like to be able to turn this:

--a file called example
test = function() --most of my APIs already use the ** = function layout, which might make things easier
  print('Test')
end

In to this:

--one big API
example = {
  test = function()
	print('test')
  end
}
example.test()

I could probably make it find an end with no tabs and put a colon, but if there's a better way to do it I'd rather do that.
Edited on 18 July 2014 - 05:29 AM
theoriginalbit #2
Posted 18 July 2014 - 08:11 AM
okay so if I'm understanding Bedrock has dependencies, but to release Bedrock you want the dependencies in the file with the Bedrock source.

Fairly easy, just use a function similar to os.loadAPI to deal with an input string as opposed to a file, then in the Bedrock file dump the contents of the dependencies into the function call so when Bedrock is loaded it will load its dependencies into the global table too; I can provide an example if you need it.
oeed #3
Posted 18 July 2014 - 09:58 AM
okay so if I'm understanding Bedrock has dependencies, but to release Bedrock you want the dependencies in the file with the Bedrock source.

Fairly easy, just use a function similar to os.loadAPI to deal with an input string as opposed to a file, then in the Bedrock file dump the contents of the dependencies into the function call so when Bedrock is loaded it will load its dependencies into the global table too; I can provide an example if you need it.

Oh of course! It seems so obvious now I think about it. That'll definitely do the job, thanks!