-
Notifications
You must be signed in to change notification settings - Fork 117
Add metatableregistry to ObjFun #60
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
base: master
Are you sure you want to change the base?
Changes from all commits
ca8fbc9
65d6d60
9fe83ce
437f0f1
6dd9cf6
8aad99a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| #pragma once | ||
|
|
||
| #include "BaseFun.h" | ||
| #include "MetatableRegistry.h" | ||
| #include <string> | ||
|
|
||
| namespace sel { | ||
|
|
@@ -10,16 +11,19 @@ class ObjFun : public BaseFun { | |
| private: | ||
| using _fun_type = std::function<Ret(Args...)>; | ||
| _fun_type _fun; | ||
| MetatableRegistry& _meta_registry; | ||
|
|
||
| public: | ||
| ObjFun(lua_State *l, | ||
| MetatableRegistry &meta_registry, | ||
| const std::string &name, | ||
| Ret(*fun)(Args...)) | ||
| : ObjFun(l, name, _fun_type{fun}) {} | ||
| : ObjFun(l, meta_registry, name, _fun_type{fun}) {} | ||
|
|
||
| ObjFun(lua_State *l, | ||
| MetatableRegistry &meta_registry, | ||
| const std::string &name, | ||
| _fun_type fun) : _fun(fun) { | ||
| _fun_type fun) : _fun(fun), _meta_registry(meta_registry) { | ||
| lua_pushlightuserdata(l, (void *)static_cast<BaseFun *>(this)); | ||
| lua_pushcclosure(l, &detail::_lua_dispatcher, 1); | ||
| lua_setfield(l, -2, name.c_str()); | ||
|
|
@@ -30,7 +34,7 @@ class ObjFun : public BaseFun { | |
| int Apply(lua_State *l) { | ||
| std::tuple<Args...> args = detail::_get_args<Args...>(l); | ||
| Ret value = detail::_lift(_fun, args); | ||
| detail::_push(l, std::forward<Ret>(value)); | ||
| detail::_push(l, _meta_registry, std::forward<Ret>(value)); | ||
| return N; | ||
| } | ||
| }; | ||
|
|
@@ -43,11 +47,13 @@ class ObjFun<0, void, Args...> : public BaseFun { | |
|
|
||
| public: | ||
| ObjFun(lua_State *l, | ||
| MetatableRegistry &dummy, | ||
| const std::string &name, | ||
| void(*fun)(Args...)) | ||
| : ObjFun(l, name, _fun_type{fun}) {} | ||
| : ObjFun(l, dummy, name, _fun_type{fun}) {} | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer just having the base constructor not have this argument and omitting the name altogether.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what do you mean? the argument is necessary because of _register_member on line 65 & 79 of Obj.h isn't it?
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right so can you make a new constructor that doesn't require it?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see. The same can be done for the Fun class, will make the change when I get a chance. |
||
|
|
||
| ObjFun(lua_State *l, | ||
| MetatableRegistry &, | ||
| const std::string &name, | ||
| _fun_type fun) : _fun(fun) { | ||
| lua_pushlightuserdata(l, (void *)static_cast<BaseFun *>(this)); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should you check if this directory exists or is set similar to how it's done to
LUA_INCLUDE_DIRabove?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the variable isn't set, link_directories won't do anything