Sol2: String module usage

Created on 18 Feb 2017  路  1Comment  路  Source: ThePhD/sol2

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?

Help.Desk

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 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)

>All comments

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)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Koncord picture Koncord  路  4Comments

morsisko picture morsisko  路  3Comments

squeek502 picture squeek502  路  4Comments

hmenke picture hmenke  路  6Comments

Murloc992 picture Murloc992  路  7Comments