[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Create Lua command line in a lua script
- From: Paul K <paulclinger@...>
- Date: Mon, 1 Jul 2013 17:55:38 -0700
Hi Milind,
> if you write an incomplete statement and execute it with pcall the lua state is still waiting for the remaining statement but if you are already in a lua state you load a string and that returns you a function so there is no direct way to know if you are ready to execute the input or not i.e. whether the input is a complete statement or incomplete. Any simple work arounds?
I think it's simpler than that. As far as I remember from reading the
source, it just checks for "'end' expected near '<eof>'" (or something
similar) as the result of the compilation, so if you see this error,
you most likely have an incomplete statement and need to ask the user
for more.
Paul.
On Mon, Jul 1, 2013 at 5:39 PM, Milind Gupta <milind.gupta@gmail.com> wrote:
> Thanks for the reply. I looked at the Lua source code already. But since
> that is in C it runs a lua state and effectively when the code is executed
> the lua state is in pause at least that is how I understood it which means
> that if you write an incomplete statement and execute it with pcall the lua
> state is still waiting for the remaining statement but if you are already in
> a lua state you load a string and that returns you a function so there is no
> direct way to know if you are ready to execute the input or not i.e. whether
> the input is a complete statement or incomplete. Any simple work arounds?
>
>
> Thanks,
> Milind
>
>
>
> On Monday, July 01, 2013 05:15:35 PM Milind Gupta wrote:
>> Hi,
>> I have a Lua program and I want to provide a terminal to the user
>> which
>> can be used as a lua interpreter command line, so that the user can
>> control
>> the program using that command line and lua code from that terminal. How
>> do
>> I make the interpreter command line in Lua to accommodate incomplete
>> lines?
>>
>> Thanks,
>> Milin
>
> What it kind of sounds like you're wanting is a Lua REPL (Read–eval–print
> loop) similar to running lua without any arguments. If that's the case, you
> may want to look at https://github.com/hoelzro/lua-repl as well (it's under
> a
> permissive license.) Otherwise, you can look directly at the lua source code
> to see how it's implemented (in src/lua.c if memory serves.)