Search code examples
luarequireworld-of-warcraft

require os, Am i missing somehting?


I come from C-family "mainstream" langages and i'm currently giving a try in Lua .

I made a simple code that check for a user entry and try to open an URL (built with user entry) in the default browser.

Saw the command os.execute("start "URL") that failed, saying that "os is undefined".

Well, seemed to be logical. I then researched the reason and discovered the "require" key word (which seems to act as a LoadLibrary or kind).

This is where I'm lost ! All forums says "yeah yeah just add require os and it will do". But it actually fail !

I obviously suspect that i am missing a "file" or path pointing at that "os" description. And that it's so obvious nobody found useful enough to explain or ask for it.

Can someone explain me what does require, in details ? Which file am i supposed to add (if i really need to ?).

If someone also have an online lesson to advise me, i'll accept it with pleasure. I feel like i'm missing a lot of basics and that's really not a "try to step-up" friendly langage


Solution

  • The standard Lua environment has os available without using require, so you must be using a non-standard Lua environment.

    When Lua is embedded into different software, access to libraries like os is usually removed, as it is a security risk. (For example, if you allowed full access to the os library to anyone using Lua on a webserver, it would mean that anyone could run random shell commands on that server.)

    If your Lua environment has been altered in this way, then there is a good chance that you will never be able to use the os library whatever you do.