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

Trying to create a new user type #1560

Open
lsproule opened this issue Dec 7, 2023 · 5 comments
Open

Trying to create a new user type #1560

lsproule opened this issue Dec 7, 2023 · 5 comments

Comments

@lsproule
Copy link

lsproule commented Dec 7, 2023

    lua.new_usertype<Command::Package>("Package",
        "new", sol::no_constructor,
        "name", &Command::Package::name,
        "git", &Command::Package::git,
        "git_short", &Command::Package::git_short,
        "git_prefixed", &Command::Package::git_prefixed,
        "selected_version", &Command::Package::selected_version,
        "versions", &Command::Package::versions,
        "target_link", &Command::Package::target_link,
        "description", &Command::Package::description,
        "selected_version", &Command::Package::selected_version,
        "git_description", &Command::Package::git_description,
        "language", &Command::Package::language,
        "license", &Command::Package::license,
        "owner", &Command::Package::owner,
        "owner_type", &Command::Package::owner_type,
        "stars", &Command::Package::stars,
        "forks", &Command::Package::forks,
        "open_issues", &Command::Package::open_issues,
        "watchers", &Command::Package::watchers
    ); 
    lua.new_usertype<Command::Project>("Project"
        "new", sol::no_constructor,
        "name", &Command::Project::project_name,
        "version", &Command::Project::project_version,
        "description", &Command::Project::project_description,
        "authors", &Command::Project::authors,
        "dependencies", &Command::Project::dependencies
    );
/home/lucas/wrk/frate/_deps/sol2-src/include/sol/function_types.hpp:110:31: error: address of overloaded function 'call' does not match required type 'int (lua_State *)'
  110 |                                 lua_CFunction freefunc = &function_detail::upvalue_this_member_variable<C, Fx>::template call<is_yielding, no_trampoline>;
      |                                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/lucas/wrk/frate/_deps/sol2-src/include/sol/function_types.hpp:268:5: note: in instantiation of function template specialization 'sol::function_detail::select_member_variable<false, false, std::vector<std::ba
sic_string<char>> Frate::Command::Project::*>' requested here
  268 |                                 select_member_variable<is_yielding, no_trampoline>(L, std::forward<Fx>(fx), std::forward<Args>(args)...);
      |                                 ^
/home/lucas/wrk/frate/_deps/sol2-src/include/sol/function_types.hpp:392:22: note: in instantiation of function template specialization 'sol::function_detail::select<false, false, std::vector<std::basic_string<char
>> Frate::Command::Project::*>' requested here
  392 |                                 function_detail::select<false, false>(L, std::forward<Args>(args)...);
      |                                                  ^
/home/lucas/wrk/frate/_deps/sol2-src/include/sol/stack_core.hpp:878:14: note: in instantiation of function template specialization 'sol::stack::unqualified_pusher<std::vector<std::basic_string<char>> Frate::Comman
d::Project::*>::push<std::vector<std::basic_string<char>> Frate::Command::Project::*>' requested here
  878 |                                 return p.push(L, std::forward<T>(t), std::forward<Args>(args)...);
      |                                          ^
/home/lucas/wrk/frate/_deps/sol2-src/include/sol/stack_field.hpp:222:7: note: in instantiation of function template specialization 'sol::stack::push<std::vector<std::basic_string<char>> Frate::Command::Project::*>
' requested here
  222 |                                                 push(L, std::forward<Value>(value));
      |                                                 ^
/home/lucas/wrk/frate/_deps/sol2-src/include/sol/stack_core.hpp:1250:59: note: in instantiation of function template specialization 'sol::stack::field_setter<char[8]>::set<const char (&)[8], std::vector<std::basic
_string<char>> Frate::Command::Project::*>' requested here
 1250 |                         field_setter<meta::unqualified_t<Key>, global, raw> {}.set(L, std::forward<Key>(key), std::forward<Value>(value), tableindex);
      |                                                                                ^
/home/lucas/wrk/frate/_deps/sol2-src/include/sol/table_core.hpp:264:14: note: (skipping 3 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all)
  264 |                                                 stack::set_field<global, raw>(L, std::forward<Key>(key), std::forward<Keys>(keys)..., table_index);
      |                                                        ^
/home/lucas/wrk/frate/_deps/sol2-src/include/sol/usertype.hpp:100:20: note: in instantiation of function template specialization 'sol::basic_table_core<false, sol::basic_reference<false>>::set<const char (&)[8], s
td::vector<std::basic_string<char>> Frate::Command::Project::*>' requested here
  100 |                                         table_base_t::set(std::forward<Key>(key), std::forward<Value>(value));
      |                                                       ^
/home/lucas/wrk/frate/_deps/sol2-src/include/sol/usertype.hpp:50:38: note: in instantiation of function template specialization 'sol::basic_usertype<Frate::Command::Project, sol::basic_reference<false>>::set<const
 char (&)[8], std::vector<std::basic_string<char>> Frate::Command::Project::*>' requested here
   50 |                         (void)detail::swallow { 0, (this->set(std::get<I * 2>(std::move(args)), std::get<I * 2 + 1>(std::move(args))), 0)... };
      |                                                           ^
/home/lucas/wrk/frate/_deps/sol2-src/include/sol/table.hpp:75:7: note: in instantiation of function temp
, 1UL, 2UL, 3UL, const char (&)[5], std::basic_string<char> Frate::Command::Project::*&&, const char (&)
:Command::Project::*&&, const char (&)[8], std::vector<std::basic_string<char>> Frate::Command::Project:
   75 |                         ut.tuple_set(std::make_index_sequence<(sizeof...(Args)) / 2>(), std::for
      |                            ^
/home/lucas/wrk/frate/_deps/sol2-src/include/sol/state_view.hpp:785:18: note: in instantiation of functi
mand::Project, const char (&)[11], const sol::no_construction &, const char (&)[5], std::basic_string<ch
char (&)[12], std::basic_string<char> Frate::Command::Project::*, const char (&)[8], std::vector<std::ba
  785 |                         return global.new_usertype<Class>(std::forward<Args>(args)...);
      |                                       ^
/home/lucas/wrk/frate/src/Generators/CMakeTemplates.cpp:86:9: note: in instantiation of function template specialization 'sol::state_view::new_usertype<Frate::Command::Project, const char (&)[11], const sol::no_co
nstruction &, const char (&)[5], std::basic_string<char> Frate::Command::Project::*, const char (&)[8], std::basic_string<char> Frate::Command::Project::*, const char (&)[12], std::basic_string<char> Frate::Comman
d::Project::*, const char (&)[8], std::vector<std::basic_string<char>> Frate::Command::Project::*>' requested here
   86 |     lua.new_usertype<Project>("Project"
      |         ^
/home/lucas/wrk/frate/_deps/sol2-src/include/sol/function_types_stateless.hpp:323:14: note: candidate template ignored: substitution failure [with is_yielding = false, no_trampoline = false]
  323 |                 static int call(lua_State* L) noexcept(std::is_nothrow_copy_assignable_v<T>) {
      |                            ^
1 warning and 5 errors generated.
make[2]: *** [CMakeFiles/frate.dir/build.make:818: CMakeFiles/frate.dir/src/Generators/CMakeTemplates.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:725: CMakeFiles/frate.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
@lsproule
Copy link
Author

lsproule commented Dec 7, 2023

Hey,
so I am writing this code
I have already done a

sol::state lua

then I am trying to add these user types. The strange thing is it compiles on another machine, but it doesn't compile on my machine. We know we have the exact same code because I am on the exact same branch as him. We were wondering what could be the cause of this issue.

@Rochet2
Copy link

Rochet2 commented Dec 17, 2023

Looks like the same issue as this #1565

@ndoxx
Copy link

ndoxx commented Dec 20, 2023

I have the same exact issue when compiling my game engine with clang-18, everything worked fine with clang-17. I'm using Lua 5.4 (latest) and the latest version of Sol2 (develop branch).
This happens when exposing a member variable directly. Maybe using sol::property instead could be a viable workaround, but in this case I have tons of code to rewrite. Is this going to be fixed?

@Rochet2
Copy link

Rochet2 commented Dec 20, 2023

I have the same exact issue when compiling my game engine with clang-18, everything worked fine with clang-17

Is Clang 18 released yet? Looks to me like 17 is latest here, which would indicate that 18 is still under development. If clang 18 is in development, then it only makes sense that there could be issues in its unreleased versions.

I have tons of code to rewrite

You can try this workaround from the ticket I linked above to see if it helps you #1565 (comment)

Is this going to be fixed?

A proper fix might need to be done in Clang itself. If I am right on what is causing this issue (the noexcept on the call function) then to me it seems like a compiler issue, not library issue.

@ndoxx
Copy link

ndoxx commented Dec 21, 2023

Thanks, got it.
I built LLVM-18 from their main branch two days ago, it's not tagged yet, anyway I'm sticking to 17 for now.
I looked at the code and I think you're right, the standard allows conversion from non-throwing function pointer to potentially throwing function pointer (just not the other way round). This clearly should not be an error.

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

3 participants