New functions in Lua


#1

I have been playing with lua for some days.
The truth that I see it interesting, coverall to make tasks at high level.

I have made some function very simple to open a channel FTP, to load a file and to keep it in flash.
This scrip I externally compress it with lua2c. I paste the bytecode in the project. It compiles correctly,
my problem comes when trying to execute the new lua function into the shell gives back the following error to me:

shell:1: variable 'lua_get_file' is not declared

:question:


#2

“variable FOOBAR is not declared” is an error caused when you use a global variable that hadn’t been declared at the top-level when you actually tried to use it.

99% of the time, when this happens, it’s a mistake:

  • either you’re trying to access a global that you’ve forgotten to create
  • or you’ve made a typo in a variable’s name (e.g. called “lua_get_file” instead of “lua_getfile”)
  • or you use a global var where you should have used a local one (thus hitting performances, and making your code vulnerable to accidental interactions)

you can fix this by declaring lua_get_file (you can do a “lua_get_file=nil” if you don’t know yet what to put in it), or if you don’t want the safety net, by removing the following line from the sample:

{ "strict",      luaopen_strict      },

Indeed, “strict” is the module which monitors undeclared globals. However, I suggest you to keep it: typos in global var names can be a serious pain in the neck to find.


#3
lua_get_file

It´s the name of my defined function. :frowning: no usues a global variables in it.
It´s necessary add the function as a new GLOBAL variable ?
it´s necessary append in luaL_Reg initializers the new function ? :question: :question:

Tanks


#4

please post your code (in private if you prefer), there’s probably a bug in it.