Giter Site home page Giter Site logo

Comments (9)

yuin avatar yuin commented on July 3, 2024

Closure serialization in GopherLua is quite hard to make it possible for some reasones.

  1. GopherLua is based on Lua5.1 : Closures in Lua5.1 refers the global environment. (Lua5.2 or newer has no global environment. The global environment is expressed as an upvalue.).
  2. GopherLua does not have bytecode dump functionality : Byte codes in Gopher are just intermediate representation.

If it is must, I'd probably try that like this:

  1. Assumptions1 : A local and remote VM share the same global variables.
  2. Assumptions2 : Closures do not have a metatable.
  3. Assumptions3 : Closures do not refer any upvalues.
  4. Dump an LFunction object into a byte array by encoding/gob ( LFunctionProto has private members, so you will have to reflections) .
  5. Load the byte array and set clo.Env = (remote global LTable) .

from gopher-lua.

xtaci avatar xtaci commented on July 3, 2024

Yes, It's hard, but it's quite useful.

Instead of distributing data, we can distribute procedures, It is much more useful than data only parallel.
All Assumptions are acceptable at this stage I think.
I really hope this feature can be added to gopher-lua.

(Assumption3. Upvalue capturing is hard, I think AST will help.)

from gopher-lua.

yuin avatar yuin commented on July 3, 2024

If it is possible to implement as a library, that should not be included GopherLua because GopherLua is Lua. Lua's philosophy is to keep itself as small as possible, but to provide functionalities that make it possible to add major language features as needed.

If you need to some functionalities to implement it, I will examine new functionalities that help you.

from gopher-lua.

xtaci avatar xtaci commented on July 3, 2024

Steps:

  1. implement function string.dump bytecode (gob maybe)
  2. getupvalues for functions
  3. (other side) setupvalues & loadstring

How do you think of this ?

from gopher-lua.

yuin avatar yuin commented on July 3, 2024

You had better stop handling upvalues.

In original Lua5.1, functions with upvalues can be dumped by string.dump, but all upvalues are initialized with nil and not shared with any other functions.
In addition, in original Lua5.0, functions with upvalues can NOT be dumped by string.dump (causes an error).

These facts underline the difficulty of handling upvalues in this job.

from gopher-lua.

xtaci avatar xtaci commented on July 3, 2024

so you still suggest manually SetGlobal(variables) & DoString(function f()) ?

from gopher-lua.

yuin avatar yuin commented on July 3, 2024

Yes, It is simplest way.
Or, write serializer for the FunctionProto struct using some reflections(yes, nearly equals to string.dump) and construct an LFunction object without upvalues(or with nil initialized upvalues).

encoding/gob will not be suitable for writing a serializer for the FunctionProto struct because it has some unexported fields.

from gopher-lua.

xtaci avatar xtaci commented on July 3, 2024

broker

this is a sample for how I use it. A name change procedure to be executed in remote.

from gopher-lua.

shabbyrobe avatar shabbyrobe commented on July 3, 2024

I have a very similar use case to this. I was thinking I could mark certain functions that I care about and extract the code from the AST, but that doesn't look possible either because the AST only contains line numbers, not token positions. Am I missing something? If not, would you accept a PR that puts the token positions into the AST?

from gopher-lua.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.