You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
« Previous
Version 17
Next »
Sometimes you might want help for methods on an object.
For instance our database library returns a database connection object that has methods with help. Iguana’s help system makes it possible to register help for these methods also.
Another example would be say you were writing a library which acts as an adapter like a “Salesforce” adapter - you authenticate and get a salesforce object that has methods on it to do things with the sales force API. Here’s some imaginary code:
local S = SALESconnect{user='fred', password=Secret}
local List = S:listCustomers{filter="ABC*"}
S:addCustomer{name="Acme", description="A generic company"}
This outlines the process:
STEP 1: Create a component and enter the translator
You probably have done this a million times now. I believe in you 😅
STEP 2: Create a new directory, call it MyLibrary
STEP 3: Create a file within that directory, call it plus1, and be sure to select the .help extension
STEP 4: Click on the new file and the Help editor will open up, it will be mostly blank
STEP 5: Click on the 3 dot menu to open the edit screen
STEP 6: Now we have to map it to the help system, create mappings.lua file.
To have this help file show up in autocompletion we now have to map it to the help system.
Create a file called mappings.lua in MyLibrary directory
Define a lua table called Methods – this is a table of methods our help system will reference
function iguana.plus1(T)
if (T.number) then
return T.number + 1
end
end
Methods.plus1 = iguana.plus1 -- map method for help
Finally, we call help.map, which takes a table with two arguments, dir and methods dir will be the directory MyLibrary we created, and methods will be our Methods table
-- map help for all functions
help.map{dir='MyLibrary',methods=Methods}
STEP 7: mappings.lua full file
local Methods = {};
function iguana.plus1(T)
if (T.number) then
return T.number + 1
end
end
Methods.plus1 = iguana.plus1 -- map method for help
-- map help for all functions
help.map{dir='MyLibrary',methods=Methods}
STEP 8: Go back to main.lua file and enter require statement
require "MyLibrary.mappings"
STEP 9: Access the help by the translator autocompletion functionality
Now, test to see if you get autocompletion for your new custom function by typing the below in the main function in main.lua.
To bring up the help page test by following the screenshot below: