lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello .. This is my first question. I'm sorry if it is obvious.

 

I'm trying to use Lua in a POS (point-of-sale) terminal, which is ARM based. The lib was compiled successfully (with a lots of warnings) and statically linked to POS project. I have a PC version of the same project only for simulation and debug.

The real problem is when I try to run a precompiled lua chunk. The code bellow runs OK on both platforms when LUASTR__ is defined, but lua_load returns a syntax error ONLY ON POS when LUASTR__ is not defined.

So the program works on POS only if parsed/compiled inside the terminal.

 

I think that the lua compiled binary is platform independent, right?

Is there some endianess issue?

 

Thank you in advance,

 

Saulo Tauil

 

//#define LUASTR__

#ifdef LUASTR__

static char testscript[] = "\r\n" "print(\"oba\")" "\r\n"; #else // Compiled with luac static const unsigned char testscript[]={

      27, 76,117, 97, 81,  0,  1,  4,  4,  4,  8,  0,  0,  0,  0,  0,  0,  0,  0,  0,

  0,  0,  0,  0,  0,  0,  2,  2,  4,  0,  0,  0,  5,  0,  0,  0, 65, 64,  0,  0,  28, 64,  0,  1, 30,  0,128,  0,  2,  0,  0,  0,  4,  6,  0,  0,  0,112,114,105, 110,116,  0,  4,  4,  0,  0,  0,111, 98, 97,  0,  0,  0,  0,  0,  0,  0,  0,  0,

  0,  0,  0,  0,  0,  0,  0,  0,

};

#endif

 

static const char *readMemFile(lua_State *L, void *ud, size_t *size) {

      // Convert the ud pointer (UserData) to a pointer of our structure

      luaMemFile *luaMF = (luaMemFile *) ud;

      // Are we done?

      if(luaMF->size == 0)

            return NULL;

      // Read everything at once

      // And set size to zero to tell the next call we're done

      *size = luaMF->size;

      luaMF->size = 0;

      // Return a pointer to the readed text

      return luaMF->text;

}

 

int main(int argc, char * argv[] )

{

      int iErr;

      char xstr[20];

      // initialize Lua

 

      pos_init();

 

      SYSLOG(1,"Iniciando...\r\n");

      //L = lua_open();

      L = lua_newstate(pos_l_alloc, NULL);

      SYSLOG(1,"fez newstate...\r\n");

      lua_register(L,"print",print);

      SYSLOG(1,"fez register print...\r\n");

      {// Test block

            luaMemFile luaMF;

            // Load the command and try to execute it...

            luaMF.text = testscript;

#ifdef LUASTR__

            luaMF.size = strlen(testscript);

#else

            luaMF.size = sizeof(testscript);

#endif

            if((iErr = lua_load(L, readMemFile, &luaMF, "test script")) == 0)

            {

                  // Execute the loaded command...

                  // The function takes 0 parameters and will return 1 result            

                  if(lua_pcall(L, 0, 1, 0) == 0)

                  {

                        lua_Number result;

                        SYSLOG(1,"fez Pcal...\r\n");

                        // There was no error

                        // Let's get the result from the stack

                        result = lua_tonumber(L, lua_gettop(L));

                  }

                  SYSLOG(1,"Fim Pcal...\r\n");

                  // Clean-up the stack

                  lua_pop(L, 1);

            }

            else

            {

                  SYSLOG(1,"NAO FEZ Load. err=%d...\r\n", iErr);

                  // There was a lua_load error...

                  // Pop the error value from the stack

                  lua_pop(L, 1);

            }

      }

 

      // cleanup Lua

      lua_close(L);

      SYSLOG(1,"fez close...\r\n");

 

      //Infinite loop!!!!

      for(;;)

      {

            sleep10(1);

            kbd_hit();

      }

      return 0;

}