title: Compiling C code with lua source
body: <pre><code>    int init_lua (char *filename,lua_State *L){
  //int inter;
  //lua_State *L = luaL_newstate();
  
  luaL_openlibs(L);
  
  if(luaL_loadfile(L, filename) ){
      error(L, "cannot run configuration file: %s",lua_tostring(L, -1)); 
      return 1;
      }
  if (lua_pcall(L, 0, 0, 0)){
      error(L, "lua_pcall() failed");
      return 2;
      }
  
  return 0;
  }
  uint8_t get_interface(unsigned int inteiro,lua_State *L){
  int inter;
  
  lua_getglobal(L,"ret_ind"); //função a ser chamada
  lua_pushnumber(L,inteiro); //argumento
  
  // do the call (1 arguments, 1 result)     
  if (lua_pcall(L, 1, 1, 0))
      error(L, "error running function 'f': %s",lua_tostring(L, -1));
  
  if (!lua_isnumber(L, -1))
      error(L, "function 'f' must return a number");
  
  inter = lua_tonumber(L, -1);
  lua_pop(L, 1);  // pop returned value /
  
  return (uint8_t)inter;
  }
  
  
  int main(void)
  {
  
  lua_State *L = luaL_newstate();
  printf("apos o load3\n");
  if (init_lua("pp.lua",L))
      printf("erro ao tentar inicializar arquivo lua\n");
  uint8_t resul;
  resul = get_interface(190,L);
  printf("Index of array: %d\n",(int)resul);
  
  resul = get_interface(10000,L);
  printf("Index of array: %d\n",(int)resul);
  
  
  return 0;
  }
  </code></pre>
  
  <p>The code above as  pp.c</p>
  
  <pre><code>interfaces = {190,3141592,10000}
  
  function ret_ind (ip)
      for i, inter in ipairs(interfaces) do
              if  inter == ip then
              return i
          end
      end
  
      return 0;
  end
  </code></pre>
  
  <p>The code above as pp.lua</p>
  
  <p>and the command to compile
  gcc -o pp pp.c -I/usr/include/lua5.1/ -llua5.1</p>
  
  <p>I'm trying to include the source of lua so I don't need have the lua installed on the machine. with the below  I can't compile once I remove the the liblua5.1-0-dev from the system.</p>
  
  <p>gcc -std=c99 -O2 -I./lua5.1/src/  pp.c -o pp.o -llua5.1</p>
  
  <p>with the library on the system I can use local source but global lua5.1 from -llua5.1.</p>
  
  <p>EDIT</p>
  
  <p>After transform the lua source code into shered object (.so) I got a executing program with:
  <i>OBS: I will put the makefile I used as a comment of this post</i></p>
  
  <p>gcc -o pp pp.c -I./lua5.1/src/ -L./lua5.1/src/ -llua5.1
  to execute the program I use 
  (must execute the 2 follows command so the ld can find the .so file)</p>
  
  <p>LD_LIBRARY_PATH=./lua5.1/src/
  export LD_LIBRARY_PATH
  and ran ./pp</p>