[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Create a new table based on an already existed table (through Lua or C API)?
- From: Peter Loveday <peter@...>
- Date: Fri, 22 Jan 2021 12:31:06 +1030
> On 22 Jan 2021, at 12:25, 孙世龙 sunshilong <sunshilong369@gmail.com> wrote:
>
>>>> Much easier to write this directly in Lua than in C.
>>> A self-defined function implemented by C makes easier for the users to
>>> deep copy a table.
>>
>> It’s no easier or harder for a user to use a C function vs a Lua function.
>> It is, however, quite a bit easier to implement these things in Lua. Doing it in C is messy.
>
> If it's implemented in Lua, it requires the users to call `require`
> function before invoking the deep copy function.
> It seems an extra work for the users. Is there any method to avoid
> this operation?
Well that’s up to your application/environment choices.
I have no idea how you’re including your C functions, whether it’s a loadable module or you’re embedding the interpreter and manually registering them... but of course you can include Lua functions in similar ways, whether that be via executing a string, a file, a module, or whatever. This may be dependent on how you intend to distribute it, whether you want to have source files visible or include them in a binary...
This is down to how you choose to structure your environment though. Given an appropriate setup, there’s no difference as far as the user is concerned… they shouldn’t need to know if they’re calling C or Lua, ideally.
- Peter