• Derma Markup Language
    35 replies, posted
To answer your question, will DML be able to convert into Lua: [b]probably not[/b]. The point of the addon is so you DON'T have to use Lua. If you want something that will generate Lua for you, I would definitely recommend DermaDesigner instead. DML is for quick and easy menus without a whole lot of dynamic content, meant more for the beginner to mid-level coders. Plus, DML --> Lua conversion would be a bitch to code.
Well, kinda late, bit this looks amazing.
While the idea is good, I don't see a point in making it use XML-ish system when Lua itself is already dynamic and would probably work better for this. (Note: this is all valid Lua syntax) [lua]local d = dml d.frame { width = 300, height = 300, title = "DML Example", color = Color(102, 102, 102), Paint = drawFrame } { d.panel { x = 10, y = 30, width = 280, height = 260, Paint = drawPanel } { d.numslider { x = 5, y = 5, width = 270, min = 0, max = 600, convar = "sv_gravity", text = "Gravity" }, d.combobox { x = 5, y = 50, width = 130, height = 180 } { -- Incoming ugly function() local ret = {} for _, pl in pairs(player.GetAll()) do ret[#ret + 1] = d.box( pl:Nick() ) end return ret end }, d.button { x = 5, y = 235, width = 130 } { "Slay" }, d.listview { x = 140, y = 50, width = 135, height = 200 } { d.column "Name", d.column "Frags", -- Ugh d.listline( function() local ret = {} for _, pl in pairs(player.GetAll()) do ret[#ret + 1] = { d.row( pl:Nick() ), d.row( pl:Frags() ) } end return ret end ) } } }[/lua] It looks cleaner in my opinion, plus it's faster and saves you ton of work :pseudo:
[QUOTE=raBBish;27601335][lua]local d = dml d.frame {...} { ... }[/lua][/QUOTE] I think you're missing something there. That calls d.frame with its parameters (the first ...) and then creates a new unrelated table that gets thrown away.
[QUOTE=immibis;27606083]I think you're missing something there. That calls d.frame with its parameters (the first ...) and then creates a new unrelated table that gets thrown away.[/QUOTE] Not at all. It calls d.frame and passes a table as the first argument (syntax similar to named arguments), the call to d.frame returns a function which takes the second table as its first argument. [editline]23rd January 2011[/editline] Hopefully this explains it better. The code is pretty much arbitrary, it's just to help explain the point. [lua]local function tablecomp(t1) return function(t2) for k, v in pairs(t1) do if v ~= t2[k] then return false end end for k, v in pairs(t2) do if v ~= t1[k] then return false end end return true end end local b = tablecomp {One = 1, Two = 2, Three = 3} { One = 1, Two = 2, Three = 4 } print(b) -- prints false [/lua] [editline]23rd January 2011[/editline] The wonders of Lua.
[QUOTE=immibis;27606083]I think you're missing something there. That calls d.frame with its parameters (the first ...) and then creates a new unrelated table that gets thrown away.[/QUOTE] Nope. d.frame is a function that takes a table as an argument, and returns a new function which takes a function too. [lua]local resultFrame local function frame( tbl ) resultFrame = {} resultFrame.Data = tbl return function( a ) resultFrame.Children = a end end frame { width = 300, height = 300, title = "DML Example" } { "test", { "test" } } for k,v in pairs( resultFrame.Children ) do print( k, v ) end[/lua] [url]http://codepad.org/fLLGKIWj[/url] Believe me, I know Lua syntactic sweetness pretty much like my own pockets :science: [editline]23rd January 2011[/editline] Maybe I wrote this a bit too long... beaten by six minutes :eng99:
Sorry, you need to Log In to post a reply to this thread.