That's... actually a really neat idea. I'm now imagining something like
function --lua strip_prefix(str,pref) --description "Strips the second arg as a
prefix from the first"
if string.sub(str, 1, #pref) == pref then
str = string.sub(str, #pref+1)
end
print(str)
return 0
end
Ideally global variables would be visible/assignable as well, although it would
not be terrible if that had to go through a map like _globals["status"] or a
function call like fish.global("status").
Math could then be implemented as a function that evaluates its arguments with
the 'math' package brought into the local namespace, e.g.
function --lua math(...) --description "Evaluates the arguments as a
mathematical expression"
local f = loadstring("return " .. table.concat({...}, ' ')
if not f then
print_err("wtf mate")
return 1
end
local env = {}
setmetatable(env, {__index=math})
setfenv(f, env)
print(f())
return 0
end
-Kevin
On Jun 22, 2012, at 4:05 AM, Maxim Gonchar <[email protected]> wrote:
>
>> I also like your suggestion of supporting "$(…)", especially because this is
>> currently a syntax error, so there's no compatibility risk. There's some
>> synergy between this and string manipulation. There could be a built-in
>> "str" or "munge" or whatever that manipulates its argument based on other
>> parameters, e.g. "(munge --strip '/*' --repeat $PWD)" to get the last
>> component of pwd.
> I had one common 'crazy' idea. Though I think it will not be supported by
> most of people I want at least to tell about it.
> Some required capabilities (like string manipulation, math and others) can be
> implemented by embedding some scripting language in fish. It may sound a bit
> strange to use one scripting language to support another one, but there are
> advantages of such an approach. While keeping fish syntax for interactive
> usage and basic scripting, the other scripting syntax will be efficient to
> solve tasks where fish syntax is not so useful.
>
> Writing this I keep in mind an example of 'lua' language. Which is created as
> tiny and fast embeddable language.
> Lua is not the only option, but since I know only it as candidate, I will
> write about advantages of using lua.
> 1) Lua (www.lua.org) is embeddable language with small memory footprint,
> clean and consistent syntax.
> It is executed by a virtual machine, which performance is comparable to
> python
> (http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=lua&lang2=python3).
> O by a very fast JIT compiler (http://luajit.org/performance_x86.html).
> 2) Out of the box it supports lua regular expressions. It's like a limited
> version of common regular expressions, but made with efficiency in mind.
> String manipulation, string matching.
> 3) The Perl regular expressions can be also included as a module.
> 4) Math functions with ability to add own functions.
> 5) Embedding lua (or some other scripting language) allows to introduce
> extendedable functions for string manipulation, math, condition testing.
> It allows to add new 'builtins' without hardcoding them and recompiling fish.
> The scripting will be also useful for writing completions or functions for
> keybinding without calling external programs.
>
> That's it.
> I'm not sure it's actually should be added to fish, but I see that there are
> a lot of benefits on this way.
>
> regards,
> Maxim
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Fish-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fish-users