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

get_or() overwriting existing table in favour of creating new one #1468

Open
Phi-21bit opened this issue Mar 27, 2023 · 0 comments
Open

get_or() overwriting existing table in favour of creating new one #1468

Phi-21bit opened this issue Mar 27, 2023 · 0 comments

Comments

@Phi-21bit
Copy link

Phi-21bit commented Mar 27, 2023

I've been doing some testing with get_or(), it seems ideal for my use case but so far it seems to fail to recognise the existing Lua table by the same name and instead chooses to create a new one overwriting the existing one. I would like to use this syntax if possible since I can't use the [ ] style in my use case
I'm assuming this function is meant to get an existing table if it exists, so I wanted to check if this is a bug or if I'm using it incorrectly

Example just for demonstration
Using Visual Studio 2022, Lua 5.4.4

#define SOL_ALL_SAFETIES_ON 1
#include <sol/sol.hpp>
int main()
{
    sol::state lua;
    lua.open_libraries(sol::lib::base);
    
    lua.script("Days = { \"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"}");
    
    sol::table daysOfWeek = lua.get_or("Days", lua.create_named_table("Days"));
    return 0;
}
    
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