ivansafrin/Polycode — Issue #89: create_lua_library causes catastrophic failure if argument named "in"
Author: mcclure
Created: 2012-01-28 07:21:36+00:00
State: open

Let's say I have a class in a header file that create_lua_library is processing...

```C++
struct MarkovModel {
void loadTraining(const string &instring);
};
```

This class gets lua-ized, everything works, I am happy. However! Let's say that instead I had used a slightly different variable name:

```C++
struct MarkovModel {
void loadTraining(const string &in);
};
```

In this case, create_lua_library will succeed, the compile will succeed, but then the program will actually crash, later, when you make the lua_require() call that loads the Markov Model crash. The console output looks like:

```
Loading custom class: Project/MarkovModel.lua
PANIC: unprotected error in call to Lua API (module 'Project/MarkovModel' not found:
no field package.preload['Project/MarkovModel']
no file './Project/MarkovModel.lua'
no file '/usr/local/share/lua/5.1/Project/MarkovModel.lua'
no file '/usr/local/share/lua/5.1/Project/MarkovModel/init.lua'
no file '/usr/local/lib/lua/5.1/Project/MarkovModel.lua'
no file '/usr/local/lib/lua/5.1/Project/MarkovModel/init.lua'
no file './Project/MarkovModel.so'
no file '/usr/local/lib/lua/5.1/Project/MarkovModel.so'
no file '/usr/local/lib/lua/5.1/loadall.so'[string "Project/MarkovModel.lua"]:18: or '...' expected near 'in')
```

This output is extremely misleading, when I accidentally named a variable "in" it took me a long time to understand that the problem was not that the generated module could not be found, but rather that the generated lua module was being found but contained a syntax error.

Expected behavior: It makes sense that if create_lua_library is directed to create variables/methods/whatever which are lua reserved words things will break, however, in this case create_lua_library should print some kind of error (a "banned words" list probably wouldn't be hard to throw together) rather than everything failing in an oblique way at runtime.