Fwd: [ANN] Lua Graphics Toolkit

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Fwd: [ANN] Lua Graphics Toolkit

Francesco Abbate
Hi all,

some times ago I have published on the web the Lua Graphics toolkit

https://github.com/franko/graph-toolkit

a Lua module for creating plots and animations with a simple
interface. It is actually a spin off of the graphical system used for
GSL Shell. I took the time to make the required changes so that it can
be used as a standalone Lua module.

With the first release the graphics toolkit was available only for
LuaJIT but now I've removed the requirement on LuaJIT so that it can
works also with standard Lua, or at least with version 5.1.

The basic instructions to test it are:
- modify the LUA variable in src/makeconfig to choose lua5.1 or luajit
- build with "make"
- build a debian package with "make debian" and install it.

The documentation is available here:

http://franko.github.io/graph-toolkit/

Someone is helping me creating a rockspec but for the moment this is not ready.

Probably there are some things to fix but the module is functional and
may be some people could be interested in it. Contributions for testing and
porting vs Lua 5.2 or even 5.3 will be welcome.

Best regards,
Francesco

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Lua Graphics Toolkit

Dirk Laurie-2
2014-12-19 20:11 GMT+02:00 Francesco Abbate <[hidden email]>:

> The documentation is available here:
>
> http://franko.github.io/graph-toolkit/

This is incredibly good documentation, complete with demonstrations.

Reply | Threaded
Open this post in threaded view
|

Global Value Content ?

Achromat
Hi together,

i extract in a debug -view the content of local variables to show them in a
editor.

how i become the content od a global variable from them name in a scriptline
?

for locals i extract the content in this example:

        CString varval,stackval,strtype;
        const char *p(0);

        for(int n(1); (p = lua_getlocal(lua, ar, n)) && (*p!='('); n++)
        {
            int type = lua_type(lua,n);

            switch(type)
            {
                case LUA_TNONE:
                     strtype  = "(illegal)";
                     stackval = strtype;
                     break;
                case LUA_TNIL:
                     strtype  = "(nil)";
                     stackval = strtype;
                     break;
                case LUA_TNUMBER:
                     strtype  = "(number)";
                     stackval.Format("%0.6f",lua_tonumber(lua,n));
                     break;
                case LUA_TBOOLEAN:
                     strtype  = "(bool)";
                     stackval.Format("%d",lua_tounsigned(lua,n));
                     break;
                case LUA_TSTRING:
                     strtype  = "(string)";
                     stackval = lua_tostring(lua,n);
                     break;
                case LUA_TTABLE:
                     strtype  = "(table)";
                     stackval = strtype;
                     break;
                case LUA_TFUNCTION:
                     strtype  = "(func)";
                     stackval = strtype;
                     break;
                case LUA_TUSERDATA:
                     strtype  = "(usrdat)";
                     stackval = strtype;
                     break;
                case LUA_TTHREAD:
                     strtype  = "(thread)";
                     stackval = strtype;
                     break;
                case LUA_TLIGHTUSERDATA:
                     strtype  = "(lightusr)";
                     stackval = strtype;
                     break;
                default:
                     break;
            }

            varval.Format("%s=%s %s",p,stackval,strtype);


Thanks for help.

Christmas greetings
Karsten

http://www.flexxvision.de/




Reply | Threaded
Open this post in threaded view
|

Re: Global Value Content ?

Sean Conner
It was thus said that the Great Karsten Schulz once stated:
> Hi together,
>
> i extract in a debug -view the content of local variables to show them in a
> editor.
>
> how i become the content od a global variable from them name in a
> scriptline ?

  If you have the name of a global, then lua_getglobal() will push the value
onto the Lua stack, which (using your code as a reference) might look like:

        /*------------------------------------------------------------------
        ; Have Lua to the heavy work of converting the type to a string for
        ; us.  To do that, we obtain the Lua function tostring() on the
        ; stack, then obtain the value of the global we have the name for.
        ; Before we call tostring() though, we get the original type of the
        ; variable.  Call tostring(), and format our output.
        ;------------------------------------------------------------------*/

        lua_getglobal(lua,"tostring");
        lua_getglobal(lua,name);
        strtype = luaL_typename(lua,-1);
        lua_call(lua,1,1);
        varval.Format("%s=%s %s",name,lua_tostring(lua,-1),strtype);
        lua_pop(lua,1);

  For a list of all globals, iterate through the global environment.  In Lua
5.2, you do something like:

        lua_pushnil(lua); /* initialize first key */
        while(lua_next(lua,LUA_RIDX_GLOBALS) != 0)
        {
          const char *name = lua_tostring(L,-2);
          lua_getglobal(lua,"tostring"); /* use tostring() to do conversion for us */
          lua_pushvalue(lua,-2); /* get value to convert */
          lua_call(lua,1,1); /* do conversion */

          /*----------------------------------------------------------------
          ; since we already have the original value on the stack, we don't
          ; need to obtain the typename before the call.  The Lua stack at
          ; this points looks like:
          ;
          ; -3 name (key for lua_next())
          ;     -2 value
          ;     -1 value as string
          ;
          ; We format the data, then pop off the two values, leaving the key
          ; for the next call to lua_next().
          ;---------------------------------------------------------------*/

          varval.Format("%s=%s %s",name,lua_tostring(lua,-1),luaL_typename(lua,-2));
          lua_pop(lua,2);
        }

  Now, if you are asking how to get a list of globals used in a function,
I'm afraid that requires a bit more work (like, parsing and building an AST,
tracking variable usage and if they're global or local---if any of this
doesn't make sense, well ... like I said, it's a bit more work).

  -spc (Merry Christmas!)


Reply | Threaded
Open this post in threaded view
|

Re: Global Value Content ?

Luiz Henrique de Figueiredo
> ; Have Lua to the heavy work of converting the type to a string for
> ; us.  To do that, we obtain the Lua function tostring() on the

You can just call luaL_tolstring, which does the what tostring does.
(tostring is implemented using luaL_tolstring.)

Reply | Threaded
Open this post in threaded view
|

Re: Global Value Content ?

Sean Conner
It was thus said that the Great Luiz Henrique de Figueiredo once stated:
> > ; Have Lua to the heavy work of converting the type to a string for
> > ; us.  To do that, we obtain the Lua function tostring() on the
>
> You can just call luaL_tolstring, which does the what tostring does.
> (tostring is implemented using luaL_tolstring.)

  Oh cool!

  -spc (I'm still using Lua 5.1, does it show?)


Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Lua Graphics Toolkit

Francesco Abbate
In reply to this post by Dirk Laurie-2
Hi Dirk,

I'm glad you like it. Actually the documentation is coming from gsl
shell, I've just stripped of the chapter, cleaned up a little bit and
added a simple example at the beginning.

Francesco