That article does show one way of doing libraries in your code. Here is what I do for libraries though:[pascal]procedure RegisterBackgroundMusic(L : Plua_State);
var
idx, mt : Integer;
begin
lua_pushliteral(L, 'BackgroundMusic');
lua_newtable(L);
idx := lua_gettop(L);
RegisterMethod(L, 'Play', @BackgroundMusic_Play, idx);
RegisterMethod(L, 'PlaySong', @BackgroundMusic_PlaySong, idx);
RegisterMethod(L, 'Stop', @BackgroundMusic_Stop, idx);
RegisterMethod(L, 'AddMusicFile', @BackgroundMusic_AddMusicFile, idx);
RegisterMethod(L, 'Delete', @BackgroundMusic_Delete, idx);
RegisterMethod(L, 'Next', @BackgroundMusic_Next, idx);
RegisterMethod(L, 'Previous', @BackgroundMusic_Previous, idx);
RegisterMethod(L, 'First', @BackgroundMusic_First, idx);
RegisterMethod(L, 'Last', @BackgroundMusic_Last, idx);
lua_newtable(L);
mt := lua_gettop(L);
RegisterMethod(L, '__index', @index_BackgroundMusic, mt);
//RegisterMethod(L, '__newindex', @index_BackgroundMusic, idx);
RegisterMethod(L, '__newindex', @newindex_BackgroundMusic, mt);
//RegisterMethod(L, '__mt', @newindex_BackgroundMusic, idx);
lua_setmetatable(L, idx);
lua_settable(L, LUA_GLOBALSINDEX);
end;[/pascal]
That should at least give you an idea of how it can work. The nice thing about Lua is there are literally 100's of ways to achieve a single task. The bad thing about Lua is there are literally 100's of ways to achieve a single task.
Sorry, that code basically creates a table called BackgroundMusic (the same thing as a library in the end). So you call methods out of it as BackgroundMusic.MethodName(Params)
Bookmarks