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

2
  • moonscript.org/reference/api.html Commented Feb 14, 2015 at 5: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. Commented Feb 14, 2015 at 7:41

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.