lua-users home
lua-l archive

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

I have a problem executing LuaSocket function when they are called
from my C program on Linux. Below an example of what I do.

http = require"socket.http"

If I execute directly theses lines in the lua interractive
interpreter, they works, but I my test.lua script called by my C
program, it generates this error:

error loading module 'socket.core' from file '/home/yop/lib/socket/':
      /home/yop/lib/socket/ undefined symbol: lua_insert

LUA_PATH and LUA_CPATH are set correctly (lua interractive works). I
use lua 5.1.1 and luasocket 2.0.1, compiled by myself with standard

Any ideas ?




#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <sys/wait.h>
#include <signal.h>

#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"

void run_file(lua_State *L, char *file)
      int error = luaL_loadfile(L, file) || lua_pcall(L, 0, 0, 0);

      if (error) {
              fprintf(stderr, "%s\n", lua_tostring(L, -1));
              lua_pop(L, 1);

int main(int argc, char *argv[])
      lua_State *L = lua_open();

      const luaL_Reg libs[] = {
        {"", luaopen_base},
        {LUA_IOLIBNAME, luaopen_io},
        {LUA_STRLIBNAME, luaopen_string},
        {LUA_MATHLIBNAME, luaopen_math},
        {LUA_TABLIBNAME, luaopen_table},
        {LUA_OSLIBNAME, luaopen_os},
        {LUA_DBLIBNAME, luaopen_debug},
        {LUA_LOADLIBNAME, luaopen_package},
        {NULL, NULL}

      const luaL_Reg *lib = libs;
      for (; lib->func; lib++) {
              lua_pushcfunction(L, lib->func);
              lua_pushstring(L, lib->name);
              lua_call(L, 1, 0);

      run_file(L, "test.lua");

      return 0;

$ gcc -Wall -O2 -g -pedantic -DDEBUG -DASCII -I/home/yop/include   -c
-o test.o test.c
$ gcc -o test test.o  -L/usr/lib -L/home/yop/lib -L. -llua -lm -ldl
$ ./test
error loading module 'socket.core' from file '/home/yop/lib/socket/':
      /home/yop/lib/socket/ undefined symbol: lua_insert