How to use library code

I'll write something up, but here are some examples in the meantime. First, define a library with variables, methods, etc. just as they would appear in app/driver:

library (
  author: "gopher.ny",
  category: "samples",
  description: "Some description",
  name: "sampleTwo",
  namespace: "samples",
  documentationLink: "http://www.google.com/"
)

void method1() {}

Then, include library anywhere in the code with #include statement, starting at the beginning of the line (no spaces before #):

#include samples.sampleTwo

That's it, include will be substituted when app/driver/library is saved. All apps/drivers using include are recompiled when include gets a change. You can click on the download icon next to Import button to see exactly how the include gets into the source code.
image

Edit: #include's parameters (if one can call them that) is namespace, followed by a dot, followed by name. Names and namespaces can include letters (upper/lower case), numbers, dots, dashes, and underscores.

4 Likes