Pthreads doesnt know $_SERVER['DOCUMENT_ROOT'] - pthreads

Please i rly need help. Im calling multiple functions with pthreads .. everything works fine but i need include file in that functions and it doesnt work because $_SERVER['DOCUMENT_ROOT'] is empty in Thread.

You can use the following anywhere in a script file to figure out your base path:
realpath(dirname(__FILE__))
Example: put this in /srv/www/domain.com/app/config.php will output:
/srv/www/domain.com/app
Make sure to use 'DIRECTORY_SEPARATOR' to add directory slashes:
realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR

Related

LUA - Calling function from other module without exporting table

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.

Lua - including file doesnt work, how can I fix it?

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!

Lua Sockets Module cpath

I'm trying to use the sockets module in a script and I keep encountering a issue where the script is unable to find socket.core. Is there anyway for me to point to exactly where the core.dll is? I've tried using cpath and I can never seem to get it to work. I just want to be able to say "C:/folder/folder/folder/core.dll"
package.cpath = 'F:/Folder/Foldertwo/Game/agame/Beta/Scripts/libs/socket/?.dll;' .. package.cpath
#EgorSkriptunoff is correct in his comment: socket.lua (which is a lua module) loads socket.core (which is a dynamic library), so you won't be able to load it from folder/core.dll as the default searcher will be looking for socket/core.dll.
If you really want to load it from folder/core.dll, you may try to load it yourself and assign the returned value to package.preload['socket.core']. This way when socket.lua loads the module, it will get the value to return from package.preload key without loading the module.

Is there any way that prevent lua from translating 'a.b' to 'a/b' when I require 'a.b'?

For example:
require('a.b.c/foo.lua')
Lua engine will translate 'a.b.c/...' to 'a/b/c/...' to search file in the pattern list, right?
Will there be any problem when 'a.b.c' are real folder name? If so, how to solve that?
If your module is located in a directory that contains . as part of its name, pulling it in with require will be difficult since there's no way to 'escape' that . so the \ substitution isn't done.
However, it may still be possible to point lua to look in the right place indirectly by playing with the package.path:
local restorepath = package.path
package.path = "./a.b.c/?.lua"
require 'foo'
package.path = restorepath
But I'd recommend that you try to reorg your project directory structure first so it better works with lua's require. Otherwise you'll have to do keep doing the above dance with other modules you might have.
Such translation is not on the spec, as far as I know. So it might work, but it might also not work. It might break on some platforms (i.e. work on Linux and Mac and not on Windows). It might work in one version of Lua and not on the next. So I would not recommend it.
The way to make sure you stay platform-agnostic is using dots everywhere. Also, I would recommend not putting the .lua part at the end, require does not always resolve that well either:
require('a.b.c.foo')

Loading lua script files in redis

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.

Resources