File tree Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change 8787 inherit ( helpers . extendedLib ) maintainers ;
8888
8989 toLuaObject = helpers . lua . toLua ;
90+ mkLuaInline = helpers . lua . mkInline ;
9091 } ;
9192in
9293helpers
Original file line number Diff line number Diff line change 3232 # and contain only letters, digits, and underscores.
3333 isIdentifier = s : ! ( isKeyword s ) && ( builtins . match "[A-Za-z_][0-9A-Za-z_]*" s ) == [ ] ;
3434
35+ # Alias for nixpkgs lib's `mkLuaInline`,
36+ # but can also convert rawLua to lua-inline
37+ mkInline = v : lib . generators . mkLuaInline ( v . __raw or v ) ;
38+
39+ # Whether the value is a lua-inline type
40+ isInline = v : v . _type or null == "lua-inline" ;
41+
3542 # toLua' with default options, aliased as toLuaObject at the top-level
3643 toLua = toLua' { } ;
3744
@@ -141,6 +148,8 @@ rec {
141148 value
142149 else if allowRawValues && value ? __raw then
143150 value
151+ else if isInline value then
152+ value
144153 else if isDerivation value then
145154 value
146155 else if isList value then
@@ -227,8 +236,11 @@ rec {
227236 v . __pretty v . val
228237 # apply raw values if allowed
229238 else if allowRawValues && v ? __raw then
230- # TODO: apply indentation to multiline raw values
239+ # TODO: deprecate in favour of inline-lua
231240 v . __raw
241+ else if isInline v then
242+ # TODO: apply indentation to multiline raw values?
243+ "(${ v . expr } )"
232244 else
233245 "{"
234246 + introSpace
Original file line number Diff line number Diff line change 6565 expected = "<lua code>" ;
6666 } ;
6767
68+ testToLuaObjectInlineLua = {
69+ expr = helpers . toLuaObject ( lib . generators . mkLuaInline "<lua code>" ) ;
70+ expected = "(<lua code>)" ;
71+ } ;
72+
73+ testToLuaObjectInlineLuaNested = {
74+ expr = helpers . toLuaObject { lua = lib . generators . mkLuaInline "<lua code>" ; } ;
75+ expected = "{ lua = (<lua code>) }" ;
76+ } ;
77+
6878 testToLuaObjectLuaTableMixingList = {
6979 expr = helpers . toLuaObject {
7080 "__unkeyed...." = "foo" ;
You can’t perform that action at this time.
0 commit comments