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

Specify (i.e. decide) what is in scope for a lua {...} block #33

Open
jparoz opened this issue Feb 25, 2023 · 0 comments
Open

Specify (i.e. decide) what is in scope for a lua {...} block #33

jparoz opened this issue Feb 25, 2023 · 0 comments
Labels
bug documentation improvement Improves the way that an existing feature works, in a backwards-compatible way.
Milestone

Comments

@jparoz
Copy link
Owner

jparoz commented Feb 25, 2023

The lua {...} syntax was intended as a sort of escape hatch, to allow for use of Lua libraries/methods/etc. which fundamentally don't have any way to model in Huck. However, it is currently unclear what exactly the programmer should expect to be in the Lua scope into which the lua block will be expanded.

In scope:

  • Any locally-bound variables in scope at the lua block (e.g. function arguments, case arm bindings)
  • Any Lua globals that your runtime provides (e.g. string.find, require, io.popen)

Is this list complete? Should there be any more items? Should any of these items not be allowed?

We can probably enforce this a bit after #31.

Here is an example of a Lua interface to be wrapped in Huck (lua_library.lua):

local Object = {}
Object.__index = Object

function Object.new()
    return setmetatable({x = 0}, Object)
end

function Object:activate()
    self.x = self.x + 1
    print("Incremented x.")
end

function Object:getVal()
    return self.x
end

return Object

Huck wrapper:

foreign import "lua_library" (new as newObject : () -> IO Object);
type Object = Object;

activateObject : Object -> IO ();
activateObject obj = lua { obj:activate() };

getObjectVal : Object -> IO Int;
getObjectVal obj = lua { obj:getVal() };
@jparoz jparoz added bug documentation improvement Improves the way that an existing feature works, in a backwards-compatible way. labels Feb 25, 2023
@jparoz jparoz added this to the 1.0.0 milestone Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug documentation improvement Improves the way that an existing feature works, in a backwards-compatible way.
Projects
Status: Todo
Development

No branches or pull requests

1 participant