1

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

Muhammad Lukman Low
  • 8,177
  • 11
  • 44
  • 54
  • http://moonscript.org/reference/api.html – hjpotter92 Feb 14 '15 at 05:22
  • 1
    You don't return a value from your `pale_moonlight.function` module, so `require` returns a `true` for you. Just put a `print_stuff` as the last line of your module to return your function instead. – siffiejoe Feb 14 '15 at 07:41

1 Answers1

4

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.

qaisjp
  • 722
  • 8
  • 31