lua.concat (Was: Simulating Lua states in Lua with only 250 lines of code)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

lua.concat (Was: Simulating Lua states in Lua with only 250 lines of code)

Dirk Laurie-2
2015-06-27 10:59 GMT+02:00 Sean Conner <[hidden email]>:

> It was thus said that the Great Nagaev Boris once stated:
>> On Sat, Jun 27, 2015 at 6:34 AM, Dirk Laurie <[hidden email]> wrote:
> I've several times asked for access
>> > to lua_concat (which respects __concat), always without success.
>>
>> Would it work like
>>
>> local a = "foo"
>> local b = "bar"
>> local c = debug.lua_concat(2)
>> print(c) --> "foobar"
>> print(a) --> nil?
>> print(b) --> nil?
>>
>> ?
>
>   I would think like:
>
>         local c = lua.concat("foo","bar","baz","blah")
>         print(c) --> "foobarbazblah"
>
> And it's not like the C code to add it would be that hard---a very simple
> implementation (that expect only strings or integers) would be:
>
>         int concat(lua_State *L)
>         {
>           lua_concat(L,lua_gettop(L));
>           return 1;
>         }

Yes, that is what I intended. I actually have a little C module like that,
which also offers stack manipulation routines like lua_pushvalue,
lua_settop etc for use in tail-call situations. And since writing modules
in the C API does not fill me with religious indignation, I can live with
that.