Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    lenscas
    @lenscas
    I want to replace local tealr_doc_gen = require(\"pages/definitions/tealr_doc_gen\") with loading it through tl.init_env. How would I do that?
    as giving tl.init_env the path as in that require just makes it unable to find stuff
    lenscas
    @lenscas

    actually, NVM.

    Though replacing it would work for .d.tl files with global records. It wouldn't work for those with local records. As tealr_doc_gen needs to support both preloading wouldn't work. So, adding that require is probably better

    Anton Bulakh
    @necauqua
    Hello!
    Are there any plans for join types (X & Y which is both X and Y)?
    Or at least basic record extension (record LargeThingWithExtraFields extends LargeThing .. end)
    Seems like this is a pretty common thing in Lua that I can't currently model (without super-verbosely/repeatedly creating new join types for every case manually)
    lenscas
    @lenscas

    not sure how X & Y would work as teal is not using a structured typing system but a nominal one.

    As for extending records: It is a feature that people want but can't agree on how exactly it would work/what it would look like.

    Hisham Muhammad
    @hishamhm
    @necauqua these two things are high on my priority list; I want to play with these ideas more concretely now that 0.14 is out, but as always no ETA on next releases. :)
    Andre-LA
    @andre_la:matrix.org
    [m]

    I made a html gen library in Teal, sharing in case it's useful for someone:

    https://github.com/andre-LA/tlpages

    lenscas
    @lenscas
    might be nice to use github pages to host an example :)
    Andre-LA
    @andre_la:matrix.org
    [m]
    I'm making my personal website on top of it, but indeed will make sense to use the gh pages with an example.
    Hisham Muhammad
    @hishamhm
    @andre_la:matrix.org cool! consider also sending a PR to add a link to it in https://github.com/teal-language/awesome-teal :)
    lenscas
    @lenscas

    in other news, tealr 0.9 is shaping up real nice. Assuming you don't want to expose your types exposed as a UserData you can now just use a macro, there is a good way to expose values to lua as a global and many more things :)

    tealr_doc_gen also has gotten a complete overhaul. .d.tl file generation can now be done by that tool which simplifies some things, and both the template for the html it produces and for the .d.tl file can be edited.

    Kai Vogelgesang
    @kaivogelgesang
    Hey ^^
    I'm currently trying to write a declaration file for use with CC: Tweaked (Minecraft mod which adds computers running LUA)
    The CC:Tweaked environment overwrites several globals like print and read, as well as the os module. So in my declaration file, the teal compiler errors because a "global was previously declared as <const>". Is there a way to disable this previous declaration (or allow overwriting it)?
    1 reply
    hisham_hm
    @hisham_hm:matrix.org
    [m]
    📣 PSA: I just committed some substantial internal changes to the type checker. If you're able to test your Teal code with the latest master, it would be useful to let me know if there are any regressions. Thanks!
    lewis6991
    @lewis6991:matrix.org
    [m]

    Just tested: I'm now getting warnings on code of the form:

    local a: {integer:any} = {}
    a[#a+1] = ...
    -- using the '#' operator on a map with numeric key type may produce unexpected results

    I understand what the warning is trying to say. But this style for appending lists is pretty typical and the behaviour is intended in this context.

    What's the best way to resolve the warning?
    aire-one
    @aire-one:matrix.org
    [m]
    I generally use table.insert(t, value)
    1 reply
    aire-one
    @aire-one:matrix.org
    [m]
    Oh and I would have typed a as a local a: { any } = {}
    lenscas
    @lenscas
    yea, I wouldn't see a {integer:T} the same as a {T}
    One reads more like a map that just happen to use integers as a key while the other is an array
    lewis6991
    @lewis6991:matrix.org
    [m]
    The issue is that the type is an array with holes
    since some elements are nil
    so you can't ipairs on it and need to run pairs instead
    hisham_hm
    @hisham_hm:matrix.org
    [m]
    lewis6991: t[#t+1] in an "array with holes" has undefined results in Lua. If you have to do this, and since you're calling it a "list", I'd still declare it as {integer} and then use pairs(a as {integer:any}).
    whenever I have to do something like this, I find that the presence of as in the code helps me identify that there's something unusual going on
    lewis6991
    @lewis6991:matrix.org
    [m]
    is table.insert defined or undefined in this case?
    hisham_hm
    @hisham_hm:matrix.org
    [m]
    it's the same. You know that it will be inserted in a nil slot, but you can't know if it's going to be after the last element or at the beginning of some hole
    lewis6991
    @lewis6991:matrix.org
    [m]
    that's fine in this case. The table is just a handle to allocated resources, to track any leaky code
    it is expected most elements get set to nil
    hisham_hm
    @hisham_hm:matrix.org
    [m]
    a = {1, 1, 1, nil, nil, 1, 1, nil, 1, 1} -- if you insert a new element into this using either method, you'll get it slotted in position 4, 8 or 11, but you can't know beforehand which.
    lewis6991
    @lewis6991:matrix.org
    [m]
    I'd expect t[#t+1] to insert into index 4
    is that not guaranteed?
    hmm, interesting
    hisham_hm
    @hisham_hm:matrix.org
    [m]
    no, it's not
    lewis6991
    @lewis6991:matrix.org
    [m]
    I thought # just counts the first n contiguous elements
    hisham_hm
    @hisham_hm:matrix.org
    [m]
    this is because the list does not store its size. # does binary search to find an "edge" nil slot in O(log n) time. It does not scan it linearly in O(n) to find the first nil.
    lewis6991
    @lewis6991:matrix.org
    [m]
    ahh, ok that makes sense
    either way, I actually don't care where the elem goes, as long as it goes in and the table can be fully iterated at some point to inspect unallocated resources
    hisham_hm
    @hisham_hm:matrix.org
    [m]
    yes, for that very particular usecase that works
    lewis6991
    @lewis6991:matrix.org
    [m]
    but I guess using # is a bit misleading
    hisham_hm
    @hisham_hm:matrix.org
    [m]
    because since you don't care where an element is (just that it's there), you can iterate using pairs, which does not guarantee ordering
    lewis6991
    @lewis6991:matrix.org
    [m]
    anyway, it's not really a problem, just a change I saw in the recent set of updates
    hisham_hm
    @hisham_hm:matrix.org
    [m]
    well, the warning ended up being informative/educational, so it's served its purpose :)
    lewis6991
    @lewis6991:matrix.org
    [m]
    I really like finding out about these edge cases in the language
    thanks!
    lenscas
    @lenscas
    in this case I would wrap the table in a custom type which exposes methods/meta_methods that do it properly
    don't have to worry about the pairs/ipairs thing or if a[#+1] behaves properly if the only way to do those things are done through dedicated methods
    jan6
    @Jan69
    hi, I don't understand how the external declaration file works, examples are only for a few records
    namely, I like candran, which compiles down to lua...but it makes functions like this
    x = function(z) -- ./src/can.can:1
      print(z) -- ./src/can.can:1
    end -- ./src/can.can:1
    comments of course irrelevant, and can be turned off, but...how am I supposed to make a declaration for that, so that, say, the argument z must be a string?
    perhaps I'm also simply misunderstanding myself
    my assumption is, if I tl check can.lua or in a teal file, require("can") or whatever, then if the file can.lua ITSELF has errors, it would report them
    jan6
    @Jan69
    if that is wrong, then I guess I based all my attempts on the wrong things entirely, lol, and also makes teal a lot less useful than I thought, as my idea was that I could write my stuff in candran (has quite a few syntax goodies), compile to lua, check with teal that everything's sane, and then run it via algernon (a web server made in Go, that includes embedded gopher-lua, which is lua 5.1 interpreter rewritten in Go)