ThePhD / sol2

Sol3 (sol2 v3.0) - a C++ <-> Lua API wrapper with advanced features and top notch performance - is here, and it's great! Documentation:
http://sol2.rtfd.io/
MIT License
4.22k stars 517 forks source link

Require is nil. Why? #1337

Closed GreedyTactician closed 2 years ago

GreedyTactician commented 2 years ago

When I run lua.script("print(require)"); in C++, I get nil printed Why?

Rochet2 commented 2 years ago

To access some functionality in lua, you need to load some libraries (math, debug, ...) For require you need package library. https://sol2.readthedocs.io/en/latest/api/state.html?highlight=open_libraries#members

Try lua.open_libraries(); to open all libraries or lua.open_libraries(sol::lib::base, sol::lib::package); to open the libraries containing print and require

I assume you already open at least the base library as you do not have any errors about printing.

GreedyTactician commented 2 years ago

Thank you!