Integrating the Lua library with some C sample code


i’m sorry i’m a very late asking these question… seems like i couldn’t compile my LuaSamples application. i wonder if my LuaSamples is the right one. because there is so many Samples in my folder. here is the source code of my LuaSamples.

#include "adl_global.h"
#include "wip.h"
#include "wiplua.h"

/* If defined, the shell wants a login/password authentication. */

/* If defined, the shell wants a password authentication (no login name). */

/* If none of the above is defined, there is no shell authentication. */

/*  Mandatory variables                                                    */
/*  wm_apmCustomStackSize                                                  */
#if __OAT_API_VERSION__ >= 400
const u16 wm_apmCustomStackSize = 4096*2;
u32 wm_apmCustomStack[1024];
const u16 wm_apmCustomStackSize = sizeof(wm_apmCustomStack);

/* Don't barf on edl_memGet() failures: */
static bool evh_openat_error(u16 errid, ascii *msg) {
  if( ADL_ERR_MEM_GET == errid) return FALSE;
  else return TRUE;

/* Go to emergency mode after 150Kb RAM have been spent: */
const int LUAW_MEM_ALARM_THRESHOLD = 150 * 1024; 

/* Reserve RAM for memory pools: */
#define WITH_POOLS
#define K 5
            LUAW_MEMPOOL_SIZE( 96*K, 20) + LUAW_MEMPOOL_SIZE( 96*K, 24) +
            LUAW_MEMPOOL_SIZE( 32*K, 28) + LUAW_MEMPOOL_SIZE( 64*K, 32) +
            LUAW_MEMPOOL_SIZE( 32*K, 76) ];

//#include "lstate.h"
//static int getmainthread( lua_State *LL) {
//  extern lua_State *L;
//  setthvalue(LL, LL->top, L);
//  LL->top++;
//  return 1;

/* What modules to load? */
static const luaL_Reg initializers[] = {

  /* Lua standard libs */
  { "base",        luaopen_base        },
  { "table",       luaopen_table       },
  { "string",      luaopen_string      },
  { "package",     luaopen_package     },
  { "debug",       luaopen_debug       },

  /* Turn undeclared global variables into errors. */
  { "strict",      luaopen_strict      },

  /* Multitasking core (mandatory) */
  { "scheduling",  luaopen_scheduling  },

  /* Timer events */
  { "timer",       luaopen_timer       },

  /* WIP: */
  { "options",     luaopen_options     },
  { "channels",    luaopen_channels    },
  { "bearers",     luaopen_bearers     },
  { "tcp",         luaopen_tcp         },

  /* Flash objects handling: */
  { "flash_read",  luaopen_flash_read  },
  { "flash_write", luaopen_flash_write },
  { "rawflash",    luaopen_rawflash    },

  /* Misc stuff. */
  { "shell",       luaopen_shell       },
  { "misc",        luaopen_misc        },
  { "at",          luaopen_at          },
  { "mem",         luaopen_mem         },
  { "print",       luaopen_print       },
  { "sms",         luaopen_sms         },
  { NULL, NULL } };

/*  Function   : adl_main                                                  */
/*  Object     : Customer application initialisation                       */
/*                                                                         */
/*  Variable Name     |IN |OUT|GLB|  Utilisation                           */
/*  InitType          | x |   |   |  Application start mode reason         */
void adl_main ( adl_InitType_e InitType ) {
  int r;

  adl_errSubscribe( evh_openat_error);

  TRACE (( 1, "Embedded Application : Main" ));

  /* Initialize the stack */
  r = wip_netInitOpts( 
      WIP_NET_OPT_SOCK_MAX,   12,
  /* Set up the memory pools: */
  wip_debug( "[LUAW][MEM] reserving %iKB for lua optimized memory pools\n", 
             sizeof( MEMPOOL)/1024);
  r = luaW_memPoolInit( MEMPOOL, sizeof( MEMPOOL),
                        32*K, 0,   8,   32*K, 0,  16,
                        96*K, 0,  20,   96*K, 0,  24,
                        32*K, 16, 28,   64*K, 20, 32,
                        32*K, 49, 76,   0);
  if( OK == r) wip_debug( "[LUAW][MEM] memory pools ready\n");    
  else         wip_debug( "\n *** Fscked-up memory pools! ***\n\n");    

  // Not compatible with older WIP versions:
  // wip_logEvents = TRUE;

  luaW_start( initializers); /* Start Lua engine */

  luaW_atLuaCmdSubscribe(); /* Register AT command AT+LUA */
  luaW_run( /* Start PPP server on UART2 */

    "global ('LOCAL_ADDR', 'PEER_ADDR', 'PPP_UART', 'LOGIN', 'PASSWORD') "

    "LOCAL_ADDR = LOCAL_ADDR or '' "
    "PEER_ADDR  = PEER_ADDR  or '' "
    "PPP_UART   = PPP_UART   or 'UART2' "
    "LOGIN      = LOGIN      or 'wipuser' "
    "PASSWORD   = PASSWORD   or '123456' "


    " = { "
    "  method = 'basic', "
    "  users = { [LOGIN] = PASSWORD } } "


    " = { method = 'basic', password=PASSWORD } "


    " "
    "wip.bearer_server (PPP_UART, { "
    "  auth_table  = { [LOGIN]=PASSWORD }, "
    "  ip_addr     = LOCAL_ADDR, "
    "  ip_dst_addr = PEER_ADDR })");


and i also wanted to ask about the PPP connection with the PC. i’m currently using a devKit for q2686 with 2 serial ports. i’m using UART1 as the PPP connection. but i don’t get the explanation in LUA tutorial about the UART2 function. would u mind explain it to me briefly?

and last, i get that before i could use the LUA scripting i should download the LUAsample into the DevKit first? am i making a mistake here? so using LUA is like using WIPSoft?




  • yes, this sample should work;
  • but I can’t tell why compilation fails if you don’t provide more details.
  • Yes, Open AT Lua is extremely similar, structurally, to WIPSoft:
    [*] it’s an Open AT plug-in library
  • you need a minimalist sample application to run it
  • you need to download that application on the WCPU to use it
  • you can taylor that application the way you want, so that it fits your needs as precisely as possible (among other to integrate C code in your Lua app: outstanding Lua/C interoperability is one of the reasons why Lua is such a killer feature for embedded development).
    ] there will be a newer version of Open AT Lua available extremely soon;[/:m]
    ] this latest version will not be optimized for WCPU with 8Mb RAM (a.k.a “256KB user application”) modules, as 16Mb (a.k.a. “1MB+ user application”) modules become the norm on Q26 and WMP based products. It will be possible but non-trivial to get it to run effectively on 8Mb products.[/*:m][/list:u]


Thx for the reply fft,

these error message appeared in my VC++,

--------------------Configuration: LUA - Win32 Wismo_Target--------------------
Loading Open AT IDE...
Loading project settings...
Building gcc_LUA_256KB project...
    Launch a full library or binary process
... Build sources filtering rules for gcc_LUA_256KB
make.exe: *** No rule to make target `appli.o', needed by `gcc_LUA_256KB'.  Stop.
[wmmake error #1] Build error.
Error executing c:\windows\system32\cmd.exe.

LUA - 1 error(s), 0 warning(s)

before this i have 3 errors occurred, 2 of them was because there was no file or directory in the folder. and i fix that by copying the needed file or directory (such as wip.h and wiplua.h) into my “out” folder. and the error was reduced into single error. but the i couldn’t understand the error, and the worst is i don’t understand the basic of makefile. therefore it would be very nice if anybody could explain to me what went wrong with my compilation. :smiley:



I’m afraid you’re being bitten by the generic “IDE V1 generation tools suite is broken beyond repair” issue. The only fix I know is to clean up by hand and regenerate with the wizard from scratch until it happens to work. You need to link together the OATLUA library, the WIP plug-in, and your sample application code, which represent a lot of potential causes of random failure :frowning: Your current “don’t know how to generate appli.o” error seems to indicate that your issue is with finding your sample application’s code.

Another approach, if you like to understand what you do and value tool reliability, is to pick up and adapt the makefiles presented here in this thread to your case (i.e. Lua + GCC, 265KB). There are working makefiles for OATLUA + ARM compiler, you’ll need to work a bit on that plus a GCC makefile to get OATLUA + GCC to work. By the way, are you sure taht you only have 256KB? AFAIK, all modules shipped now come with 1MB+ RAM, which is much more comfortable for Lua.

No, I’m afraid that the worst is that absolutely nobody on Earth understands Open AT makefile generation, including at Wavecom…

Finally, the long term approach is to wait for IDE v2 which has a sane building suite, but I don’t think it will be available before months.

The first person to have a working OATLUA + GCC Makefile would be extremely kind to submit it on the forum or on the wiki. I might give it a try, but not now :frowning:


Hi fft,

i don’t get it when you said that no one in this world know the makefile process in Open AT. because i think the creator of this Open AT certainly will know what’s going on inside of his/her application. :smiley: . by the way when you said that i must clean up by hand my application and regenerate all of the wizard things until it all work out, did you mean that i must remake all my LUA samples from scratch again? or should i re-install my Open AT in my PC?
and about the plugins. when i make my WIPSoft application using the Open AT Wizard, there was an option box inside of the Wizard that should be filled with the appropriate plug-ins (in that case it was WIP 4.00.2080). but there was no option for LUA inside of it. shouldn’t i get that option for LUA samples application? because i think that was the source of my problem.



when you said that i must clean up by hand my application and regenerate all of the wizard things

I mean only keeping the subdirectories with your sources (normally src and itf), your wmnew.opt, and optionally the *.scs file (by double-clicking it you’ll launch the wizard in the right directory). The problem is that WIP is properly packaged as a plug-in, but as a user you have no way to package a library as a plug-in, so you won’t have the option to simply check an option in the wizard.

How to add a library “manually” in the wizard:

Here you want to add the oatlua library to the dependencies of your OAT application project. That’s done by adding the following options in the “wmnew script additional options” box at the lower left corner of the wizard dialog:

-rootlib C:/path/to/the/liibrary/oatlua -inc C:/path/to/the/library/oatlua/itf -libpref oatlua

That would be supposing that a single person designed, maintained, understood and documented the application generation scripts :slight_smile:


Hi fft,

Thank you so much. i’m going to give it a go right no. should there’ll be another problem occured i might trouble you with more questions. i hope you don’t mind.

Best regards,


You now have a simpler solution than compiling the lib from sources: download the packaged plug-in, referenced from this post.