Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_package_loader without lua_CFunction #1601

Open
Gerark opened this issue Apr 27, 2024 · 0 comments
Open

add_package_loader without lua_CFunction #1601

Gerark opened this issue Apr 27, 2024 · 0 comments

Comments

@Gerark
Copy link

Gerark commented Apr 27, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant