Wednesday, July 28, 2010

Lua C-API

Yesterday I've restarted to develop a rts-game from the scratch. I've decided to use LUA as script engine. Because I want use C++ as programming language, I wrote a binder class to bind C++-Classes with Lua-Metatables. The first thing I needed to learn was that you can't call all functions of the C-API directly. Some of them must be called during a lua-call. If they be called directly you will often get an error like "PANIC: unprotected error in call to Lua API (no calling environment)" and your application will crash immediately. It tooks a long time until I noticed that I can't call
lua_replace(L, LUA_ENVIRONINDEX);
directly so I must use
lua_setfenv(L, -1);
if I want to set the current table as environment table. You will get the same error message if you try to load single libs (luaopen_..) directly. You must use luaL_openlibs or open it during a lua call.

Greetz,
BlueC0re

No comments:

Post a Comment