I've seen the code example of how to use the add_package_loader but I'm not sure if I can use it by passing a simpler lambda.
This is what I'm trying to do:
luaState.add_package_loader([this](std::string_view moduleToLoad) {
if (moduleToLoad == "bindings.input") {
return sol::make_object(luaState, luaState.create_table_with(
"doSomething", [](){}
));
}
return sol::make_object(luaState, "This is not the module you're looking for!");
});
local input = require "bindings.input"
input.doSomething()
The lambda is called successfully with the right value in the moduleToLoad. But for some reason I still get this error:
An unexpected error has occurred: sol: runtime error: ..scripts\core\input.lua:2: module 'bindings.input' not found:
no field package.preload['bindings.input']
Am I supposed to only pass lua_CFunction to the add_package_loader or is it just my approach missing something?
I've seen the code example of how to use the
add_package_loader
but I'm not sure if I can use it by passing a simpler lambda.This is what I'm trying to do:
The lambda is called successfully with the right value in the moduleToLoad. But for some reason I still get this error:
Am I supposed to only pass lua_CFunction to the
add_package_loader
or is it just my approach missing something?