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

Create apis without unloading or setting apis

Started by EveryOS, 01 March 2016 - 04:36 PM
EveryOS #1
Posted 01 March 2016 - 05:36 PM
I can't get the pictures to show up??
Sometimes a program will create Apis without having to be set as Apis. For example, the shell.


You can also do this. For example, I did it:



To do this follow these steps:
Enter somewhere that runs Lua:
type:
lua

Create an index:
type:
myIndex={}

Make Your Index Global:
type:
_G.myIndex = myIndex\

Make a function under the index:
type:
myIndex.myFunction(){print('test');}

test your function
type:
myIndex.myFunction()

You can also do this in the edit program:
Edited on 01 March 2016 - 04:42 PM
KingofGamesYami #2
Posted 01 March 2016 - 06:08 PM

myIndex.myFunction(){print('test');}

Is not valid lua. This is:


myIndex.myFunction() print('test'); end
wilcomega #3
Posted 05 March 2016 - 04:18 PM
also you need to either use the set operator or the fuction keyword like so:

myIndex.myFunction = function() print('test') end
function myIndex.myFunction() print('test') end