Skip to content

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

@jparoz

Description

@jparoz

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() };

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdocumentationimprovementImproves the way that an existing feature works, in a backwards-compatible way.

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions