Giter VIP home page Giter VIP logo

Comments (4)

Elv13 avatar Elv13 commented on August 17, 2024
[11:30] <psychon> I wonder if we can come up with something that is "transparent" to uses in rc.lua
[11:31] <Elv1313> psychon: yes, but it will require being able to set custom metatables for client
[11:31] <Elv1313> that way we can use __index to hijack .border_width and __newindex for the setter. Then it wont break the API and just work
[11:31] <normalra> Exactly.
[11:31] <psychon> hm... might be a good idea to have
[11:32] <psychon> well, rather than setting the metatable, it might be easier to be able to set handlers for __index and __newindex for "property misses" (when the C code doesn't know how to handle things)
[11:32] <Elv1313> I tried to implement that the other day, but ran out of time without much results (I don't know the luac API that well)
[11:32] <Elv1313> psychon: yes, that would work
[11:35] <psychon> "just" requires patching luaA_class_newindex() and luaA_class_index()
[11:35] <psychon> instead of calling newindex_miss_property, they'd need to call into some lua function (that somehow lua must be able to set earlier...)
[11:38] <Elv1313> psychon: if you take care of the C side, I will implement the handlers. I already have the code in Radical to do just that
[11:38] <Elv1313> it also emulate :set_foo(x) -> object.foo = x
[11:41] <Elv1313> psychon: do you want me to create an issue for that?
[11:41] <psychon> yeah, feel free
[11:41] <psychon> and we need to come up with some API for lua to set the handlers
[11:41] <psychon> does it make sense to have them object-specific? or is it ok to have it just per-class?
[11:43] <Elv1313> I guess client, tag, screen, drawable, key and drawin should have the same API
[11:43] <psychon> looking forward to your feature requests which includes explanations on how the API might look like :-P
[11:47] <phryk> Do things like wibox or the widgets use lua classes and I just find lua confusing or are they implemented as just a bunch of functions?
[11:48] <Elv1313> psychon: https://github.com/awesomeWM/awesome/issues/163
[11:48] <psychon> phryk: lua doesn't have a built-in concept of a "class"
[11:48] <psychon> Elv1313: thanks, will take a look on saturday

from awesome.

psychon avatar psychon commented on August 17, 2024

See psychon@e091381 and the following code that can be added to the default config:

-- For experiments with the error handling:
local check_errors = false

if check_errors then
    drawin.set_index_miss_handler(function(...) error("Nope") end)
    drawin.set_newindex_miss_handler(function(...) error("Nope") end)
else
    drawin.set_index_miss_handler(function(...) print("index miss", ...) return print, 42 end)
    drawin.set_newindex_miss_handler(function(...) print("newindex miss", ...) return 42 end)
end

d = drawin({})
print("getting d.foo")
print(d.foo)
print("setting d.bar = 7")
d.bar = 7
-- This would call nil
if not check_errors then
    print("calling foobar")
    print(d:foobar("calling foobar"))
end

I used .set_index_miss_handler(func) instead of .index_miss_handler = func because this is easier on the C side. There is already support for adding functions to all objects (for the .instances() and signal handling functions), but hijacking _index and _newindex on classes would be more complicated.

I didn't add a getter because I'm lazy and would rather have a single place in lua where something is implemented based on this instead of modules "chaining calls" to each other (get old handler, set your own which calls the old handler if it doesn't know what to do).

I didn't add this set_index_miss_handler to individual objects, but only to classes (c vs client), since I'm lazy and this approach here is already complicated enough IMO.

Does this still seem ok? Anyone wants to experiment with this code?

from awesome.

psychon avatar psychon commented on August 17, 2024

See the discussion at #482 and especially #482 (comment).

from awesome.

psychon avatar psychon commented on August 17, 2024

Fixed with #482 and #757

from awesome.

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.