Embedding Lua in C++ #7 - Using Native Types in Lua

preview_player
Показать описание
These videos describe how to embed Lua into a native application and interface with the Lua C API. They do not cover how to use the scripting language itself.

The stub project for these videos is available here.

The tutorial is on Windows and using CMake and Visual Studio, but you could build this code on pretty much any platform.
Рекомендации по теме
Комментарии
Автор

This is fantastic. Thank you for putting this up. Important to note that getglobal pushes the user data onto the stack and if this call to getglobal was inadvertently inside a loop without calling lua_pop(L, 1); at the end of each iteration it would cause a stack overflow. my2c

DamianReloaded
Автор

6:00 this is not how i would create userdatas
what i would do is this

Sprite* spr = new Sprite();
lua_pushlightuserdata(L, spr);

reason i'd do it like this is because userdatas get gced if they go out of scope like you said(ive had this happen before and almost pulled my hair out)
so if you want to save it and use it for later u advise u to use this method ^^

uhnoyearsago
Автор

I'm far from an accomplished C++ programmer - but the combination of C++17 lambda syntax with C-style (casts) looks odd to me. Is there a particular reason to use them rather than, say, `static_cast<Sprite*>(…)`?

It's an academic point though - thanks for the series!

RoamingAdhocrat
Автор

I just found out in D that `int delegate(lua_State *L)`s crash the program so I'm going to have to write my own scripting language somehow.

ismailAx
join shbcf.ru