Skip to content
Discussion options

You must be logged in to vote

Functions can't go into the state from your async code. Everything you pass into or return from a ya.sync() block crosses threads, and only sendable values can make that trip: nil, booleans, numbers, strings, Url, and tables of those. A method is a function, so it gets rejected, and a metatable isn't carried across either.

You can still have op:undo(), though. Keep the data sendable and the behavior in your plugin. Store a plain record with a kind, then attach the methods with a metatable after you read it back:

-- Behavior lives at module level and never crosses threads.
local Op = {}
Op.__index = Op

local undo_by_kind = {
	rename = function(op) --[[ move op.to back to op.from ]] end,
	m…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@drewlwhitney
Comment options

Answer selected by drewlwhitney
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
1. Q&A
Labels
None yet
2 participants