How to require and use moonscript functions

459 Views Asked by At

This looks very simple but has me stumped, I have a function like this:

print_stuff = (name) -> name

defined in a folder called pale_moonlight so it's here: pale_moonlight/function.moon. When I try calling it like this:

> f = require 'pale_moonlight.function'
> f.print_stuff 'lolo'

I get the error below:

[string "tmp"]:1: attempt to index global 'f' (a boolean value)

What is the proper way to do this? My moonscript version: 0.2.6, lua version: 5.2.3

1

There are 1 best solutions below

0
On

The last line of your file should be { :print_stuff }. This is MoonScript for: return { print_stuff = print_stuff } and allows the function to be accessed through the table that would be returned by require.