I have tried :
c(module_name).
: but this only works from the shell, and gives an error when I try to run it from within a module.
If you want exactly that behaviour, c:c(module_name) will call the same function called by the shell. I would hesitate to put code that calls user_default (c) functions in production code, so you might want to look at the source for the function and replicate it in your own code so you don't get bitten by a behaviour change in a future erlang release.
You might want to have a look to the compile module and to the compile:file/2 function in specific.
Related
So, I want to use scrapy-splash with endpoint='execute' but mimic endpoint='render.html' with my Lua extra code. But I couldn't find an example how this should be done so that the Lua code that will be sent with the request will be the same as the Lua (I expect) used to intercept an HTML with all it's parameters.
Any idea?
As far as I could see this is not supported, but I have found this
https://github.com/scrapinghub/splash/blob/master/splash/tests/lua_modules/emulation.lua script which mimics the actual python code that runs render.html (and other endpoints).
This (should) allow mimicing (as much as possible) the python code that runs render.html and should be easy to extend with lua/js code.
Note: you want to add the following lines at the bottom of emulation.lua:
function main(splash)
return {
html = emulation.render_html(splash)
}
end
Important: you must add --disable-lua-sandbox to splash (docker) command line
I try to setup a special behavior with Jitsi, but have not that much LUA knowlege.
A Jitsi/Prosody module "mod_muc_lobby_rooms.lua" is implementing some function like handle_create_lobby(event);. handle_create_lobby is calling other sub-function from inside.
https://github.com/jitsi/jitsi-meet/blob/master/resources/prosody-plugins/mod_muc_lobby_rooms.lua
But the module itself is not a library module, so no table is exported and another code can use "require". So my understanding from LUA yet.
For a own module, I just want use this functions from the other side, without reimplement or copy/paste it.
Is there any solution, how I can "source" the function into my module?
If possible, I want let "mod_muc_lobby_room.lua" unchanged, if some updates from Jitsi are coming.
Thanks in advance.
A lua beginner, Uwe
You can fire an event because it listen for it.
prosody.events.fire_event("create-lobby-room", event)
Or you can use the module function like this:
local muc_lobby_rooms = module:depends("muc_lobby_rooms");
muc_lobby_rooms.handle_create_lobby(event);
You can do it like that:
file=io.open("mod_muc_lobby_room.lua")
io.input(file)
load(io.read("*a"))()
io.close(file)
And the code located in mod_muc_lobby_room.lua will be executed.
So I straight up copy and pasted the code from the Erlang docs: https://erlang.org/doc/reference_manual/modules.html#module-syntax
Please help!
The module didn't compiled. To fix it try this in the Erlang shell (eshell):
1> c(m).
ok
2> m:fact(1).
1
See documentation on how code loading works.
exception error: undefined shell command
almost always means that the shell environment does not have the intended function, which can also mean that the module which contains its definition has not been loaded for all the code that we write by our hand and execute. You can deliberately try to misspell some auto loaded BIF(s) for example "length1" and you will still see same message showing up.
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.
My delphi application runs scripts using JvInterpreter (from the Jedi project).
A feature I use is runtime evaluation of expressions.
Script Example:
[...]
ShowMessage(X_SomeName);
[...]
JvInterpreter doesn't know X_SomeName.
When X_SomeName's value is required the scripter calls its OnGetValue-callback.
This points to a function I handle. There I lookup X_SomeName's value and return it.
Then JvInterpreter calls ShowMessage with the value I provided.
Now I consider switching to DelphiWebScript since it has a proper debug-interface and should also be faster than JvInterpreter.
Problem: I didn't find any obvious way to implement what JvInterpreter does with its OnGetValue/OnSetValue functions, though.
X_SomeName should be considered (and actually is, most of the time) a variable which is handled by the host application.
Any Ideas?
Thanks!
You can do that through the language extension mechanism, which has a FindUnknownName method that allows to register symbols on the spot.
It is used in the asm lib module demo, and you can also check the new "AutoExternalValues" test case in ULanguageExtensionTests, which should be closer to what you're after.