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

A way to call functions within an API?

Started by SGunner2014, 22 February 2015 - 05:48 PM
SGunner2014 #1
Posted 22 February 2015 - 06:48 PM
Hello,

I was trying to make an API for creating GUIs, but I need a way to call a function from the program that loaded the API from the API itself. If that makes any sense at all, could you help please? :P/>

Thanks,
- Sam
Lyqyd #2
Posted 22 February 2015 - 06:51 PM
Why do you need this? There's probably a better way to do it.

You could always just pass the function to the API, of course.
SGunner2014 #3
Posted 22 February 2015 - 06:57 PM
Why do you need this? There's probably a better way to do it.

You could always just pass the function to the API, of course.

Okay, the API loads in the file which contains the buttons and their details (position, name, action, etc). It then draws these to the screen. It enters a loop, where it will run until the user clicks on a position which has a button on it. It is then meant to run the function specified in the file that it loaded in earlier. However, I need a way so as to be able to run said function from the main program which is using the API.

Thanks,
- Sam
Lyqyd #4
Posted 22 February 2015 - 07:01 PM
Oh, if the other file is written in valid Lua, you can just load it up and execute it, then take the contents of the resulting fenv table, similar to how os.loadAPI works.