🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Linking SDL to lua

Started by
0 comments, last by Monder 20 years ago
i'm writing a game in c++... i also use some lua5 embedded scripts with it.. it works fine but now i'm stuck with graphics. i'd like to use sdl with my project and call some or all functions from scripts. still i don't know how i could easiest use sdl with lua5. yes i know luasdl and loadmodule but it confuses me - loadmodule seems to be made only to lua4... i searched newsgroups, somebody said that loadmodule is included in lua5, it is bullshit: ./main.scr:5: attempt to call global `loadmodule' (a nil value) have i forgot to load something in c++ program? is there anybody who could give a step-by-step instruction to link sdl to lua5? pardon my english - "sultan of turkey"
Advertisement
From the LUA manual

Quote: loadlib (libname, funcname)

Links the program with the dynamic C library libname. Inside this library, looks for a function funcname and returns this function as a C function.

libname must be the complete file name of the C library, including any eventual path and extension.

This function is not supported by ANSI C. As such, it is only available on some platforms (Windows, Linux, Solaris, BSD, plus other Unix systems that support the dlfcn standard).


That may be what you're looking for, however it won't help you much with SDL as the functions is loads have to take a lua_state and return the amount of values returned on the stack (which SDL functions do not do). To link SDL to LUA you'll have to write wrapper functions that can be called by the LUA script and then call SDL. You'll also have to write functions that can grab table data from lua and put them in structs that SDL can use and vice versa. To simplify this process you can use a C->Lua binding libary, there's a few listed on this page, CaLua or LuaBind should be able to do what you want. A quick google search also turned up this which is SDL bindings for LUA, no idea how good they are though.

This topic is closed to new replies.

Advertisement