6

I am relatively new to Lua, and am experimenting with embedding it in a library. I can execute the script just fine from the command line, but I hit the following error when calling a function in my script when embedded

PANIC: unprotected error in call to Lua API ([string "-- #! /usr/local/bin/lua..."]:72: attempt to call global 'unpack' (a nil value))

Where did unpack go?

Clifford
  • 88,407
  • 13
  • 85
  • 165
learnvst
  • 15,455
  • 16
  • 74
  • 121
  • 12
    Check the versions of Lua you are using. In Lua 5.1, `unpack` was a global, but in 5.2 it's been moved to `table.unpack`. You might be using Lua 5.1 in the command line while embedding 5.2. – Colonel Thirty Two Sep 11 '14 at 18:13
  • Hmm moving it to table.unpack worked. I'm using 5.2.3 for both the embedded and command line interpreters. The command line interpreter did not seem to care that I left `unpack` unqualified. – learnvst Sep 11 '14 at 18:27

1 Answers1

9

You're probably embedding Lua as source, not as a pre-built library. In this case, you have probably not enabled backward compatibility.

By default, the command line interpreter is built with backward compatibility, hence the difference you see.

lhf
  • 70,581
  • 9
  • 108
  • 149