-
-
Notifications
You must be signed in to change notification settings - Fork 471
Function as argument #2942
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?
Function as argument #2942
Conversation
add function type to read and write method define static `CallFunction` method and `CleanupFunction` method
define methods
define methods
define methods
couldn't you just implicit convert functions to refs using |
i think i couldn't understand well what you mean |
No news about this PR? I can't imagine a cases for what need store functions in elementData, but for exports it very useful. 🤔 |
This reminds me of #3551 |
{ | ||
lua_newtable(luaVM); // create callable | ||
|
||
lua_pushresource(luaVM, m_pResource); // push function inside callable |
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.
When a referenced resource become stopped this pointer will turn into the dangling one. From what I was able to see there is no an invalidation mechanism for functions.
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.
i agree
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.
i have some cleaner and better version in my mind for this
i will work on it and update its PR to use that instead
I consider this feature as excessive and the implementation as dangerous. |
i need time to refactor this PR |
I'm opposed to this. There's no good reason for this to exist, it can be dangerous AND it can cause easy memory leaks. |
hi guys
i could made a method that help lua to pass a function as argument and send it to other resources
and you can use it in both server and client sides
you can pass function as argument in
triggerEvent
orexports.resource:func_name
orsetElementData(if you set 4th argument to false)
and send it to another resource and call itand also you can send functions in table (but you can't share metamethods)
for example:
when you pass a function as an argument it will look like a table
and has these values:
-- function reference:
.resource : the resource that owns function
.reference : the reference id
.free : this method deletes the reference. if you call it, means that you won't be able to use that function anymore
note 1 : you can store a function reference in other resource if you want to let it be active otherwise if you call that function in render event or sth like that and you don't use
:free
method, after seconds your game or server console crashs because it occupies your memorynote 2 : remember when you want to cleanup your function call it as method, like
function:free
(not likefunction.free
) becausefree
needs a callable value as first argument