Panic on attempt to index a string value

Author: ligurioCreated Feb 17, 2025Updated Feb 17, 2025

Please answer the following before submitting your issue:

  • What version of GopherLua are you using? : ccacf662c9d24821ea6cb1abaa515cc3b6aad7c6
  • What version of Go are you using? : 1.23.6
  • What operating system and processor architecture are you using? : Ubuntu 24.04 amd64
  • What did you do? : See below
  • What did you expect to see? : See below
  • What did you see instead? : See below

The Lua source code below

lua
debug.setmetatable('string', {})
do ('Lua').key = 1 end;

triggers a panic in GopherLua:

lua
$ /home/sergeyb/sources/go/bin/glua -e "
debug.setmetatable('string', {})
do ('Lua').key = 1 end;
"
runtime error: invalid memory address or nil pointer dereference
stack traceback:
        <string>:3: in main chunk
        [G]: ?

The same snippet executed by Lua 5.1 reports an error "attempt to index a string value":

lua
$ lua5.1 -e "
debug.setmetatable('string', {})
do ('Lua').key = 1 end;
"
lua5.1: (command line):3: attempt to index a string value
stack traceback:
        (command line):3: in main chunk
        [C]: ?