New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repl wanted #79

Closed
TitanSnow opened this Issue May 1, 2017 · 26 comments

Comments

Projects
None yet
2 participants
@TitanSnow
Contributor

TitanSnow commented May 1, 2017

Feature Request

repl needed to write & test script more easily

That is, each time I wanna do something, for example have a look at path.join(), I have to write a simple statement to a file then use xmake lua to run it. That's troublesome. A repl like other script languages have is good-to-use

I tried to impl it by myself but it has trouble with sandbox

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi May 1, 2017

Member

This is a very nice feature, I also wanted to add this feature before. I saw the implementation of luajit.c, It seems not very complicated, I will attempt to implement it in this week if everything goes well.

Member

waruqi commented May 1, 2017

This is a very nice feature, I also wanted to add this feature before. I saw the implementation of luajit.c, It seems not very complicated, I will attempt to implement it in this week if everything goes well.

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow May 1, 2017

Contributor

👍

Contributor

TitanSnow commented May 1, 2017

👍

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi May 2, 2017

Member

I have finished this feature on linux/macosx. (not yet tested it on windows)

You can fetch dev branch and run xmake lua to run interactive commands. for example:

$ xmake lua

> import("core.project.task")
> task.run("hello")
>
> print(path.join("/tmp", "xxx"))
>
> = 1+2+3 / 4
>
> a = 1
> print(a)
>
> for _, v in pairs({1, 2, 3}) do
>> print(v)
>> end
Member

waruqi commented May 2, 2017

I have finished this feature on linux/macosx. (not yet tested it on windows)

You can fetch dev branch and run xmake lua to run interactive commands. for example:

$ xmake lua

> import("core.project.task")
> task.run("hello")
>
> print(path.join("/tmp", "xxx"))
>
> = 1+2+3 / 4
>
> a = 1
> print(a)
>
> for _, v in pairs({1, 2, 3}) do
>> print(v)
>> end
@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow May 2, 2017

Contributor
> 1
stdin:1: unexpected symbol near '1'
> a=1
> a
>> 

I think a single val should be printed directly

like python:

>>> 1
1
>>> a=1
>>> a
1
Contributor

TitanSnow commented May 2, 2017

> 1
stdin:1: unexpected symbol near '1'
> a=1
> a
>> 

I think a single val should be printed directly

like python:

>>> 1
1
>>> a=1
>>> a
1
@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow May 2, 2017

Contributor

Anyway 👍

Contributor

TitanSnow commented May 2, 2017

Anyway 👍

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi May 3, 2017

Member

@TitanSnow I agree with your point, but I don't know how to distinguish them better in lua.

So you need add prefix character '=' to eval expr now.

> = 1 + 3 +5
9
> = 1
1

Or you can help me improve it. interactive.c:168

Member

waruqi commented May 3, 2017

@TitanSnow I agree with your point, but I don't know how to distinguish them better in lua.

So you need add prefix character '=' to eval expr now.

> = 1 + 3 +5
9
> = 1
1

Or you can help me improve it. interactive.c:168

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow May 3, 2017

Contributor

I'd like to look into it 😃

Contributor

TitanSnow commented May 3, 2017

I'd like to look into it 😃

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow May 3, 2017

Contributor

I found some info on stackoverflow that might be workable

Contributor

TitanSnow commented May 3, 2017

I found some info on stackoverflow that might be workable

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow May 3, 2017

Contributor

lua 5.3 uses pre-check to know whether a statement could return

  const char *retline = lua_pushfstring(L, "return %s;", line);
  int status = luaL_loadbuffer(L, retline, strlen(retline), "=stdin");
  if (status == LUA_OK) {
    // ...

at lua.c:334 (5.3.4)

if could return then add return otherwise not add return

Contributor

TitanSnow commented May 3, 2017

lua 5.3 uses pre-check to know whether a statement could return

  const char *retline = lua_pushfstring(L, "return %s;", line);
  int status = luaL_loadbuffer(L, retline, strlen(retline), "=stdin");
  if (status == LUA_OK) {
    // ...

at lua.c:334 (5.3.4)

if could return then add return otherwise not add return

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi May 3, 2017

Member

@TitanSnow I tried this way before, but this method can't handle some function calls well. for example:

> import("core.project.task")
> task.run("xxx")  <------ will failed, task not found

These function calls can also be returned, but return import("...") cannot affect the scope of the outside

Member

waruqi commented May 3, 2017

@TitanSnow I tried this way before, but this method can't handle some function calls well. for example:

> import("core.project.task")
> task.run("xxx")  <------ will failed, task not found

These function calls can also be returned, but return import("...") cannot affect the scope of the outside

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow May 3, 2017

Contributor

@waruqi That's too bad 😞 I couldn't figure out why it will be so -- return break scope? Maybe lua is a magic language that makes me 🌀

Contributor

TitanSnow commented May 3, 2017

@waruqi That's too bad 😞 I couldn't figure out why it will be so -- return break scope? Maybe lua is a magic language that makes me 🌀

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi May 3, 2017

Member

@TitanSnow And it's hard to distinguish whether you want to print the return value. Any function call that has a return value will be printed

for example:

function test()
    -- do some thing

    -- ok
    return true
end

then, we run it using return test()

> test()
true      -- maybe I don't want to see this return value
Member

waruqi commented May 3, 2017

@TitanSnow And it's hard to distinguish whether you want to print the return value. Any function call that has a return value will be printed

for example:

function test()
    -- do some thing

    -- ok
    return true
end

then, we run it using return test()

> test()
true      -- maybe I don't want to see this return value

@waruqi waruqi added the discussion label May 3, 2017

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow May 3, 2017

Contributor

I think now there are two thing needed to be done:

  • in multiline input, I need a cancel way. <C-C>?

  • the readline library itself is common in posix system but the headers might be not. On my ubuntu, unless libreadline-dev is installed, there's no header readline/*

    there are two solutions:

    • add require of readline development files
    • do not include the header. Declare them manually:
      diff --git a/core/src/xmake/sandbox/interactive.c b/core/src/xmake/sandbox/interactive.c
      index 339ab9cc..da3c7a8e 100644
      --- a/core/src/xmake/sandbox/interactive.c
      +++ b/core/src/xmake/sandbox/interactive.c
      @@ -41,8 +41,8 @@
        */
       #include "prefix.h"
       #ifndef TB_CONFIG_OS_WINDOWS
      -#   include <readline/readline.h>
      -#   include <readline/history.h>
      +    extern char* readline   (const char*);
      +    extern void  add_history(const char*);
       #endif
      
       /* //////////////////////////////////////////////////////////////////////////////////////
Contributor

TitanSnow commented May 3, 2017

I think now there are two thing needed to be done:

  • in multiline input, I need a cancel way. <C-C>?

  • the readline library itself is common in posix system but the headers might be not. On my ubuntu, unless libreadline-dev is installed, there's no header readline/*

    there are two solutions:

    • add require of readline development files
    • do not include the header. Declare them manually:
      diff --git a/core/src/xmake/sandbox/interactive.c b/core/src/xmake/sandbox/interactive.c
      index 339ab9cc..da3c7a8e 100644
      --- a/core/src/xmake/sandbox/interactive.c
      +++ b/core/src/xmake/sandbox/interactive.c
      @@ -41,8 +41,8 @@
        */
       #include "prefix.h"
       #ifndef TB_CONFIG_OS_WINDOWS
      -#   include <readline/readline.h>
      -#   include <readline/history.h>
      +    extern char* readline   (const char*);
      +    extern void  add_history(const char*);
       #endif
      
       /* //////////////////////////////////////////////////////////////////////////////////////
@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi May 4, 2017

Member

@TitanSnow It try loading return expr first now. You can try it.

> 1 + 2
3

> a = 1
> a
1

But you need assign var manually when call import now.

> task = import("core.project.task")
> task.run("hello")
Member

waruqi commented May 4, 2017

@TitanSnow It try loading return expr first now. You can try it.

> 1 + 2
3

> a = 1
> a
1

But you need assign var manually when call import now.

> task = import("core.project.task")
> task.run("hello")
@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi May 4, 2017

Member

@TitanSnow

  • in multiline input, I need a cancel way. ?

Use the signal to cancel multiline, this way is too much trouble and can not handle the cross-platform well.

So you can simply input q to cancel multiline input, for example:

> for _, v in ipairs({1, 2}) do
>> print(v)
>> q             <--  cancel multiline and clear previous input
> 1 + 2
3
  • the readline library itself is common in posix system but the headers might be not. On my ubuntu, unless libreadline-dev is installed, there's no header readline/*

I fixed it

+    extern char* readline   (const char*);
+    extern void  add_history(const char*);
Member

waruqi commented May 4, 2017

@TitanSnow

  • in multiline input, I need a cancel way. ?

Use the signal to cancel multiline, this way is too much trouble and can not handle the cross-platform well.

So you can simply input q to cancel multiline input, for example:

> for _, v in ipairs({1, 2}) do
>> print(v)
>> q             <--  cancel multiline and clear previous input
> 1 + 2
3
  • the readline library itself is common in posix system but the headers might be not. On my ubuntu, unless libreadline-dev is installed, there's no header readline/*

I fixed it

+    extern char* readline   (const char*);
+    extern void  add_history(const char*);
@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow May 4, 2017

Contributor

👍

Contributor

TitanSnow commented May 4, 2017

👍

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow May 6, 2017

Contributor

A very bad message: I tested carefully again, found that although libreadline has installed, xmake couldn't build successfully even declare functions manually, libreadline-dev is required. And libreadline-dev is not one of build-essential package group. So that install scripts must be modified to add this requirement @waruqi

Contributor

TitanSnow commented May 6, 2017

A very bad message: I tested carefully again, found that although libreadline has installed, xmake couldn't build successfully even declare functions manually, libreadline-dev is required. And libreadline-dev is not one of build-essential package group. So that install scripts must be modified to add this requirement @waruqi

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi May 6, 2017

Member

@TitanSnow But it passed on ci.Can you give me some build error info? I try to fix it and detect libreadline . If this library not found, I will continue to uses fgets when building.

Member

waruqi commented May 6, 2017

@TitanSnow But it passed on ci.Can you give me some build error info? I try to fix it and detect libreadline . If this library not found, I will continue to uses fgets when building.

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow
Contributor

TitanSnow commented May 6, 2017

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow May 6, 2017

Contributor

Three solutions:

  • fallback to fgets (reduce user experience)
  • install this library via package manager if not found (troublesome)
  • bundle readline (impossible because license)
Contributor

TitanSnow commented May 6, 2017

Three solutions:

  • fallback to fgets (reduce user experience)
  • install this library via package manager if not found (troublesome)
  • bundle readline (impossible because license)
@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi May 6, 2017

Member

ok, I will fix it in recent days.

Member

waruqi commented May 6, 2017

ok, I will fix it in recent days.

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi May 6, 2017

Member

@TitanSnow I want to use the following two solutions:

  1. Try detect libreadline.a before building, I will use fgets if readline not found. (It done)
  2. Modify get.sh to install this library via package manager if not found (Can you help me modify it?)
Member

waruqi commented May 6, 2017

@TitanSnow I want to use the following two solutions:

  1. Try detect libreadline.a before building, I will use fgets if readline not found. (It done)
  2. Modify get.sh to install this library via package manager if not found (Can you help me modify it?)
@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow May 6, 2017

Contributor

👌

Contributor

TitanSnow commented May 6, 2017

👌

@TitanSnow TitanSnow referenced this issue May 7, 2017

Merged

detect readline #80

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi May 7, 2017

Member

@TitanSnow Thanks! 😸

Member

waruqi commented May 7, 2017

@TitanSnow Thanks! 😸

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow May 8, 2017

Contributor
$ xmake --version
XMake v2.1.4.201705081849, The Make-like Build Utility based on Lua
Copyright (C) 2015-2016 Ruki Wang, tboox.org, xmake.io
Copyright (C) 2005-2015 Mike Pall, luajit.org
$ xmake lua
> os.execv('git',{'--version'})
git version 2.11.0
> os.runv
function: 0xb71601e8
> os.runv('git',{'--version'})
/usr/local/share/xmake/core/base/os.lua:569: runv(git --version) failed(-1)!
stack traceback:
	[C]: in function 'error'
	/usr/local/share/xmake/core/base/os.lua:569: in function 'raise'
	/usr/local/share/xmake/core/sandbox/modules/os.lua:245: in function </usr/local/share/xmake/core/sandbox/modules/os.lua:237>
	[C]: in function 'interactive'
	...ake/core/sandbox/modules/import/core/sandbox/sandbox.lua:51: in function 'interactive'
	/usr/local/share/xmake/plugins/lua/xmake.lua:60: in function </usr/local/share/xmake/plugins/lua/xmake.lua:32>
	[C]: in function 'load'
	/usr/local/share/xmake/core/project/task.lua:423: in function 'run'
	/usr/local/share/xmake/core/main.lua:188: in function </usr/local/share/xmake/core/main.lua:151>
> 

?

Contributor

TitanSnow commented May 8, 2017

$ xmake --version
XMake v2.1.4.201705081849, The Make-like Build Utility based on Lua
Copyright (C) 2015-2016 Ruki Wang, tboox.org, xmake.io
Copyright (C) 2005-2015 Mike Pall, luajit.org
$ xmake lua
> os.execv('git',{'--version'})
git version 2.11.0
> os.runv
function: 0xb71601e8
> os.runv('git',{'--version'})
/usr/local/share/xmake/core/base/os.lua:569: runv(git --version) failed(-1)!
stack traceback:
	[C]: in function 'error'
	/usr/local/share/xmake/core/base/os.lua:569: in function 'raise'
	/usr/local/share/xmake/core/sandbox/modules/os.lua:245: in function </usr/local/share/xmake/core/sandbox/modules/os.lua:237>
	[C]: in function 'interactive'
	...ake/core/sandbox/modules/import/core/sandbox/sandbox.lua:51: in function 'interactive'
	/usr/local/share/xmake/plugins/lua/xmake.lua:60: in function </usr/local/share/xmake/plugins/lua/xmake.lua:32>
	[C]: in function 'load'
	/usr/local/share/xmake/core/project/task.lua:423: in function 'run'
	/usr/local/share/xmake/core/main.lua:188: in function </usr/local/share/xmake/core/main.lua:151>
> 

?

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi May 8, 2017

Member

@TitanSnow I have fixed it.

Member

waruqi commented May 8, 2017

@TitanSnow I have fixed it.

@TitanSnow TitanSnow closed this May 9, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment