How about this one?
if debug.getinfo(3) then print("in package") else print("in main script") end
Same idea, less keystrokes. Level 3 as argument is sufficient, because debug.getinfo is not called within another function.
debug.getinfo