Hi, I'm finding difficulty using the string module and was wondering if I could get some help.
In my lua code:
string = require("string")
str = string.lower("HeLLO")
str2 = string.reverse("world")
In my cpp file:
sol::state lua;
sol::load_result script1 = lua.load_file( "script.lua" );
script1(); //execute
std::string str = lua["str"];
std::string str2 = lua["str2"];
But for both str, and str2, I am given values of "". Am I perhaps missing anything?
You need to load the Lua libraries you intend to use with lua.open_libraries. To load all base Lua libraries, you can use lua.open_libraries(). To load specific libraries, you can do something like lua.open_libraries(sol::lib::base, sol::lib::string) (see the state docs for the full list)
Most helpful comment
You need to load the Lua libraries you intend to use with
lua.open_libraries. To load all base Lua libraries, you can uselua.open_libraries(). To load specific libraries, you can do something likelua.open_libraries(sol::lib::base, sol::lib::string)(see thestatedocs for the full list)