I know how to load a Lua file via luaL_loadbuffer. Now I have many Lua files, more than 100. I am thinking about how to speed up the loading process. One way I figured out is: put all files into one, and then load this file using luaL_loadbuffer (I did some tests, but just got syntax error return by luaL_loadbuffer). Does anyone ever use this method? Or is there any other way to speed up the loading?
Expanding on #siffiejoe's comment and this answer to a related SO question, I use Squish to collapse multiple modules into a single .lua file. You can then use luac to compile it into bytecode, if desired.
I replaced Lua with LuaJIT and the loading time reduced to ~6sec. I'm satisfied with this result now.Thanks everybody.
Related
I have a problem with lua include (dofile, loadfile, require). What I want to do is including file to my main lua file.
Main file - stala_2enb_lua.lua
File to include - zmienne_2enb_modyfikacja
I want to have my main file constant and make changes only in second file, where I want to have variables.
Main file
File to include
I tried all ways like on the screen, but I have no output. It behaves like this all including doesnt matter. There is no error and the variables are not included. How can I make it correctly?
UPDATE
I've managed to load a little bit using dofile, but there is an error which I can't understand. I've found a solution, but i can't understand it properly --> devdocs.io/nginx_lua_module --> ctrf +f = Lua Coroutine Yielding/Resuming
Error after loading function using dofile ("/home/epcsim/WTS_2001_WK05/zmienne_2enb_lua.lua")
Thanks in advance for the help!
I obfuscated this script using some site
But i'm wondering how to deobfuscate it? can someone help me?
i tried using most decompilers and a lot of ways but none has worked
local howtoDEOBFUSCATEthis_Illll='2d2d341be85c64062f4287f90df25edffd08ec003b5d9491e1db542a356f64a488a1015c2a6b6d4596f2fa74fd602d30b0ecb05f4d768cd9b54d8463b39729eb1fe84630c0f8983f1a0087681fe4f2b322450ce07b
something like that for an example.
the whole script: https://pastebin.com/raw/fDGKYrH7
First reformat into a sane layout. a newline before every local and end will do a lot. Then indenting the functions that become visible is pretty easy.
After that use search replace to inline constants. For example: local howtoDEOBFUSCATEthis_IlIlIIlIlIlI=8480; means you can replace every howtoDEOBFUSCATEthis_IlIlIIlIlIlI with 8480. Though be careful about assignments to it. If there are any then it's better to rename the variable something sensible.
If an identifier has no match you can delete the statement.
Eventually you get to functions that are actually used.
Looking at the code it seems to be an interpreter implementation. I believe it's a lua interpreter
Which means that you'll need to verify that and decompile what the interpreter executes.
I have an nspire calculator and after writing a hash table implementation, found the BASIC environment to be a pretty offensive programming environment. Unfortunately, as far as I'm aware, it's impossible to use Lua to write libraries.
I did see that somewhere in the Lua interface you can detect variable changes so it might be possible within a file to use Lua functions, but I fear it will go out of scope if used externally.
Is there a better way to do this?
It's not impossible to write Lua libraries for a TI-Nspire. You can put the libraries code into a string, store it as a variable in TI-Basic and put the file in the MyLibs folder. Then, when you want to load your library, do loadstring(var.recall("libfilename/programstring"))(). This will load the library's code as a string from that files, compile it (using loadstring), and execute it (practicaly the same as require).
Also, about getting from controlling a Lua script using TI-Basic, depending on what you want to do, you could use math.eval("<some TI-Basic code>"). This will execute the code in TI-Basic, and return the result as a Lua value (or string). This way, you can call a TI-Basic function every once in a while, and act according to its output.
I want to make a small "library" to be used by my future maxima scripts, but I am not quite sure on how to proceed (I use wxMaxima). Maxima's documentation covers the save(), load() and loadFile() functions, yet does not provide examples. Therefore, I am not sure whether I am using the proper/best way or not. My current solution, which is based on this post, stores my library in the *.lisp format.
As a simple example, let's say that my library defines the cosSin(x) function. I open a new session and define this function as
(%i0) cosSin(x) := cos(x) * sin(x);
I then save it to a lisp file located in the /tmp/ directory.
(%i1) save("/tmp/lib.lisp");
I then open a new instance of maxima and load the library
(%i0) loadfile("/tmp/lib.lisp");
The cosSin(x) is now defined and can be called
(%i1) cosSin(%pi/4)
(%o1) 1/2
However, I noticed that a substantial number of the libraries shipped with maxima are of *.mac format: the /usr/share/maxima/5.37.2/share/ directory contains 428 *.mac files and 516 *.lisp files. Is it a better format? How would I generate such files?
More generally, what are the different ways a library can be saved and loaded? What is the recommended approach?
Usually people put the functions they need in a file name something.mac and then load("something.mac"); loads the functions into Maxima.
A file can contain any number of functions. A file can load other files, so if you have somethingA.mac and somethingB.mac, then you can have another file that just says load("somethingA.mac"); load("somethingB.mac");.
One can also create Lisp files and load them too, but it is not required to write functions in Lisp.
Unless you are specifically interested in writing Lisp functions, my advice is to write your functions in the Maxima language and put them in a file, using an ordinary text editor. Also, I recommend that you don't use save to save the functions to a file as Lisp code; just type the functions into a file, as Maxima code, with a plain text editor.
Take a look at the files in share to get a feeling for how other people have gone about it. I am looking right now at share/contrib/ggf.mac and I see it has a lengthy comment header describing its purpose -- such comments are always a good idea.
For principiants, like me,
Menu Edit:configure:Startup commands
Copy all the functions you have verified in the first box (this will write your wxmaxima-init.mac in the location indicated below)
Restart Wxmaxima.
Now you can access the functions whitout any load() command
Could someone give an example of how to load and execute .lua script files in windows. I am using ServiceStack redis to loadluascript. It works to certain scripts which don't have module(...) like things.
I am getting this error
Error compiling script (new function): user_script:5: cannot use '...' outside a
vararg function near '...' , sPort: 61688, LastCommand:
Any help by giving an example would be highly appreciated.
Thanks in advance
It would help if you posted the Lua script you are trying to load or execute.
Three dots don't have anything to do with modules:
Vararg expressions, denoted by three dots ('...'), can only be used
when directly inside a vararg function
I guess this answers your question: your Lua code is simply invalid.
Speaking of modules: you can't load your own modules in Redis Lua, which you might already know. See http://redis.io Scripting.
The solution for the above kind Lua script is to prepend local before a function or all variables. I took out the module thing and tweaked the Lua script to make it work. Later I realized the script will not be any use to me :). Thanks for looking into this post.