lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sat, Mar 18, 2017 at 3:49 AM, Martin <eden_martin_fuhrspam@gmx.de> wrote:
> On 03/17/2017 01:19 PM, Sean Conner wrote:
>>> Lua is missing simple but
>>> powerful string manipulation functions as the Basic has.
>>
>>   What?  All I recall of BASIC string manipulations are LEFT$(), RIGHT$(),
>> MID$() and STRING$(), all of which can be replaced with string.sub() in Lua.
>> I recall those being pretty typical of the time.
>
> There are more.
>
> LEFT$/RIGHT$/MID$ - get part of string
>   ~ string.sub
> MID$ - set part of string
>   ~ string.gsub
> LEN
>   ~ string.len, # operator
> LTRIM$/RTRIM$ - trim spaces
>   ~ string.gsub
> LCASE$/UCASE$
>   ~ string.(lower/upper)
> INSTR - find substring
>   ~ string.find
> STR$/VAL/HEX$/OCT$
>   ~ tonumber/tostring
> ASC/CHR$
>   ~ string.(char/byte)
> STRING$/SPACE$ - repeat one char <n> times,
>   ~ string.rep
> MKI$/CVI/... - codecs to internal number formats (int, dbl, float, ...)
>   ~ string.(pack/unpack)
>
> Generally I feel Lua functions more generic, more powerful and
> harder to master.
>
> Surely they are completely different languages. Lua is a more
> language itself, with central abstractions on tables, first-type
> functions and variable code. While QBASIC is a fixed interface to
> hardware that was available at that time. Lua is good for processing
> complex data structures while QBASIC is good for implementing UI.
>
> (BTW for Lua is a nice library Love2D which affords similar
> functionality as QBASIC - almost direct access to hardware without
> predefined UI elements.)
>
> (And I think that niche for data processing are still almost empty.
> Only regexps are there. (And probably map/reduce.))
>
> (Yes, we can do anything with C/Go/Pascal/Ada/.. but sometimes
> marginal simplicity and narrower application field are needed to
> implement complex things.)
>
> -- Martin
>

Most of those functions aren't present in traditional BASIC
implementations. The trim, case, find, and packing functions are
certainly not present.

/s/ Adam