[Iup-users] Is there a stand-alone Lua+X11+Motif+IUP interpreter?

Otfried Cheong otfried.iup at ipe.airpost.net
Mon Oct 8 22:16:32 GMT+3 2007


> My question is:  Is there a sample version of such a "base
> application" that I could play with?  For example, is there a version
> of the stand-alone Lua interpreter that has been modified to include
> the X11, Motif and IUP libraries?
> 
> Or is there some other sample application that is a good starting
> point for playing with IUP+Lua on Linux?

This page:

http://www.tecgraf.puc-rio.br/iup/en/sys_guide.html#iuplua

has a basic example of a program that includes the interpreter, opens 
IUP and the Lua bindings, and then executes your own Lua file.

Unfortunately "iuplua5_init.c" has not been updated for Lua 5.1 and 
actually crashed on my machine until I learnt enough about the Lua API 
to update it (the culprit was luaopen_io(L), you are not allowed to call 
it like this anymore in Lua 5.1).

Below is my own version of this program, modified for Lua 5.1 and to 
take the script name from the command line.   Try it with "samples.lua" 
from

http://www.tecgraf.puc-rio.br/iup/en/samples.html

This is the most complete sample with various widgets, but there are 
short Lua snippets demonstrating virtually all IUP controls linked from 
the IUP documentation.

If you want an interactive Lua interpreter with IUP bindings, just copy 
the "IupOpen" incantation into "lua.c" (from the Lua distribution itself).

Hope this helps,
  Otfried


// --------------------------------------------------------------------
// lua.cpp
// --------------------------------------------------------------------

extern "C" {
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
}

#include <iup.h>
#include <iuplua.h>

#include <stdlib.h>

// --------------------------------------------------------------------

int main(int argc, char **argv)
{
   if (argc < 2) {
     fprintf(stderr, "Usage: lua <script.lua> [ <arguments> ]\n");
     exit(1);
   }

   IupOpen();
   IupSetLanguage("ENGLISH");

   lua_State *L = luaL_newstate();
   luaL_openlibs(L);
   iuplua_open(L);

   // create table with arguments
   lua_createtable(L, argc - 2, 0);
   for (int i = 2; i < argc; ++i) {
     lua_pushstring(L, argv[i]);
     lua_rawseti(L, -2, i - 1);
   }
   lua_setglobal(L, "argv");

   iuplua_dofile(L, argv[1]);

   IupMainLoop();

   lua_close(L);
   IupClose();

   return 0;
}

// --------------------------------------------------------------------




More information about the iup-users mailing list