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

[1.79] executeMainThreadTask strips ILuaObject #125

Open
SquidDev opened this issue Jul 6, 2016 · 0 comments
Open

[1.79] executeMainThreadTask strips ILuaObject #125

SquidDev opened this issue Jul 6, 2016 · 0 comments

Comments

@SquidDev
Copy link
Contributor

SquidDev commented Jul 6, 2016

Returning instances of ILuaObject from ILuaContext.executeMainThreadTask strips instances of ILuaObject. This is because the object is converted to a table of functions, which are converted then converted to null. I'm not sure this is easily fixable, I'm just documenting this issue in case others hit it.

To get around this I've been creating a "pointer" class, storing to it, and then returning its result in the parent method.

Example

public class Foo implements ILuaObject {
  public Object[] callMethod(ILuaContext context, int method, Object[] args) 
    throws LuaException, InterruptedException {
    // Returns an empty table instead.
    return context.executeMainThreadTask(new ILuaTask() {
      public Object[] execute() throws LuaException { return Foo.this; }
    });
  }
}
SquidDev added a commit to cc-tweaked/CC-Tweaked that referenced this issue Dec 15, 2022
I've been meaning to fix this for over 6 years, and just kept
forgetting.

Previously ILuaContext.executeMainThreadTask worked by running
ILuaContext.issueMainThreadTask, pulling task_complete events, and then
returning the results.

While this makes the implementation simple, it means that the task's
results were converted into Lua values (in order to queue the event) and
then back into Java ones (when the event was pulled), before eventually
being converted into Lua once more.

Not only is this inefficient, as roundtripping isn't lossless, you
couldn't return functions or rich objects from main thread functions
(see dan200/ComputerCraft#125).

We now store the return value on the Java side and then return that when
the receiving the task_complete event - the event no longer carries the
result. Note this does not affect methods using issueMainThreadTask!
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