both define an init function and other functions with similar names.
First of all, why are these features global? They must be local to the script. If you are going to require them in other files, they must create and return a table containing the functions that they want to open.
The modern idiom requiring these files is to do something like this:
local Library = require 'library' Library.Func1(...)
This way you are not polluting the global Lua namespace. You are using local variables.
However, if you insist on using such global globals, you can do exactly what the documentation says: change the first upvalue of the compiled fragment.
Basically, if I replace setenv with setuservalue, I get an access violation.
Of course yes. This is not what lua_setuservalue does. It is designed to set values ββassociated with user data. What you want is called lua_setupvalue .
Using the code sample that you are quoting, the correct answer would be:
lua_setupvalue(L, -2, 1);
Nicol bolas
source share