lua-users home
lua-l archive

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


Aren't you requiring taboo.lua from taboo.lua?


On Thu, May 30, 2013 at 11:54 PM, Chris Tetreault <forums@doingmyprogramming.com> wrote:
I had such a strange issue, I felt compelled to share. I'm working on a simple lua C library for a blog entry I'm working on, and apparently you can't name a lua C library "taboo". The following is my library code:

#ifndef TABOO_H
#define    TABOO_H

#ifdef    __cplusplus
extern "C" {
#endif

#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
   
    static int test_string(lua_State * L);
    int luaopen_taboo(lua_State * L);
   

#ifdef    __cplusplus
}
#endif

 -----------------------------------------------------

#include <string.h>
#include "taboo.h"

static int test_string(lua_State * L){
    const char * test_val = lua_tostring(L, -1);
    if (strcmp("foo", test_val) || strcmp("bar", test_val)){
        lua_pushboolean(L, 1);
        return 1;
    }
    else{
        lua_pushboolean(L, 0);
        return 1;
    }
    return 0;
}


static const struct luaL_Reg test [] = {
    {"test_string", test_string},
    {NULL, NULL}
};

int luaopen_taboo(lua_State * L){
    luaL_newlib(L, test);
    lua_setglobal(L, "test");
    return 0;
}

... installed like so ...

sudo mv NetBeansProjects/taboo/dist/Debug/GNU-Linux-x86/libtaboo.so /usr/local/lib/lua/5.2/abcde.so

... and my script ...

#!/home/chris/lua/bin/lua

require("taboo")

print(test.test_string("foo"))
print(test.test_string("words"))

... when run, outputs ...

./taboo.lua
/home/chris/lua/bin/lua: error loading module 'taboo' from file './taboo.lua':
    ./taboo.lua:5: too many C levels (limit is 200) in main function near '"foo"'
stack traceback:
    [C]: in ?
    [C]: in function 'require'
    ./taboo.lua:3: in main chunk
    [C]: in function 'require'
    ./taboo.lua:3: in main chunk
    [C]: in function 'require'
    ./taboo.lua:3: in main chunk
    [C]: in function 'require'
    ./taboo.lua:3: in main chunk
    [C]: in function 'require'
    ...
    [C]: in function 'require'
    ./taboo.lua:3: in main chunk
    [C]: in function 'require'
    ./taboo.lua:3: in main chunk
    [C]: in function 'require'
    ./taboo.lua:3: in main chunk
    [C]: in function 'require'
    ./taboo.lua:3: in main chunk
    [C]: in function 'require'
    ./taboo.lua:3: in main chunk
    [C]: in ?

If I change the library name to literally anything else, it works fine. I'm fairly new to lua, so I may be missing something. But I can't think of any reason why this should be happening. Have I found some obscure bug, or am I on crack?