Embedding Lua in C++ Part 3: Meh... Just use Sol...

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 มี.ค. 2024
  • In this video, I show how to use the excelent Sol library/wrapper to integrate Lua in your C++ program. This is shown in direct contrast to how i did it in Part #1 which was bare bones, from scratch.
    Source: github.com/OneLoneCoder/Javid...
    Patreon: / javidx9
    TH-cam: / javidx9
    / javidx9extra
    Discord: / discord
    Twitter: / javidx9
    Twitch: / javidx9
    GitHub: www.github.com/onelonecoder
    Homepage: www.onelonecoder.com
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 72

  • @frodo_alaska
    @frodo_alaska หลายเดือนก่อน +39

    Yeah, Javid's channel is a core part of a C++ programmer's toolbelt at this point. Not only are you videos calming and laid back (something that's hard to find these days), but you also have A LOT of interesting ideas in terms of projects. I can't tell you how many project ideas of yours I... uhhh... "borrowed" and implemented my own way. So, as a young programmer and a C++ connoisseur, thank you. And rock on!

    • @javidx9
      @javidx9  หลายเดือนก่อน +5

      Rock on Frodo! 😂

    • @phutureproof
      @phutureproof หลายเดือนก่อน +1

      it's rare these days that someone says "a lot", so I wanted to hi 5 you for that 👍

    • @frodo_alaska
      @frodo_alaska หลายเดือนก่อน +1

      @@phutureproof Yeah I like saying a lot a lot.

  • @optimizt8555
    @optimizt8555 หลายเดือนก่อน +29

    Sol is one of the first libraries where I realized modern C++ can be used to create great APIs; I was almost skeptical when I assigned C++ functions or objects to tables and it just worked on the other side without me needing to explicitly tell it much. A lot of other host languages can't eliminate huge chunks of the boilerplate in the same way because they don't have the same template machinery and type information that C++ does.

    • @outsider1st
      @outsider1st หลายเดือนก่อน +5

      and it's a total template hell, but it's still great :D

    • @noxagonal
      @noxagonal หลายเดือนก่อน

      ​​@@outsider1stI think the complexity is partly historical. It can be made simpler however. Eg. Type packs are awesome but also pretty complex, I made my own TypeList class to help me interrogate and iterate over types. I think, incremental improvements is the way to go, at least with C++.

  • @jcugnoni
    @jcugnoni หลายเดือนก่อน +6

    This video and Sol libraries are just so clear and easy to comprehend that I want to go back to my old c++ project and implement Lua scripting just for the fun of it ;-)

  • @motbus3
    @motbus3 หลายเดือนก่อน +10

    Woooow. Happy to see OLC here. I hope family and you are doing well!

    • @javidx9
      @javidx9  หลายเดือนก่อน +6

      Doing great thanks!

  • @solstice_enigma
    @solstice_enigma หลายเดือนก่อน +2

    Oh, I've been waiting for this! So thrilled to see more new videos on the channel, they're so informative and fun to watch. Hope that you are doing great.

  • @delusionalaar4031
    @delusionalaar4031 หลายเดือนก่อน +5

    Ugh, I love this series and your TH-cam videos. I don’t know how to show any more appreciation other than just my words

  • @jsflood
    @jsflood หลายเดือนก่อน +2

    Great video! Sol library sure is greatly simplifying and unconfusinating the embedding of LUA to C++ for the programmer. Thank you Javid for sharing.

  • @KerboOnYT
    @KerboOnYT หลายเดือนก่อน

    Always nice to see a OLC video and learn something. I hope you're well and thanks for making these when you have time

  • @SYNAPSEdwl
    @SYNAPSEdwl หลายเดือนก่อน +1

    All the best Javid, thank you very much for your great work you did.

  • @etan4732
    @etan4732 23 วันที่ผ่านมา

    This video came at the perfect time as I've just started making my own game engine. I was about the use the raw Lua C libraries but my word Sol is so intuitive!

  • @Phroggster
    @Phroggster หลายเดือนก่อน +1

    It's nice to see a software video today that isn't talking about the ssh backdoor that just came to light. Thank you Javid, I greatly appreciate your upload and hope that you're doing well!

  • @MoolsDogTwoOfficial
    @MoolsDogTwoOfficial หลายเดือนก่อน +2

    Love your channel mate!

  • @minirop
    @minirop หลายเดือนก่อน

    I have been using sol for years now and it's always a pleasure to use.

  • @oblivion_2852
    @oblivion_2852 หลายเดือนก่อน +1

    Being able to just index into the table instead of having to play with the stack looks so useful

  • @CybAtSteam
    @CybAtSteam หลายเดือนก่อน

    Very nice, i was not aware of the Sol library. This will come in handy :)

  • @huseyinkucuk3909
    @huseyinkucuk3909 หลายเดือนก่อน +5

    Thanks Javidx9

  • @kyoai
    @kyoai หลายเดือนก่อน +14

    Sol is such a great wrapper for Lua, I can't imagine using Lua without it.

    • @HolyMethWizard
      @HolyMethWizard หลายเดือนก่อน +2

      On God, I didn't want to deal with embedding Lua. Sol was basically just plug and play

  • @barellevy6030
    @barellevy6030 หลายเดือนก่อน +1

    Don’t have time to watch today, just dropped to like and comment❤

  • @cadfoot568
    @cadfoot568 หลายเดือนก่อน +11

    Better call Sol. Sorry I had to

    • @ohdude6643
      @ohdude6643 หลายเดือนก่อน

      Give this man a proper drink! I salute you sir!

    • @xerox8521
      @xerox8521 หลายเดือนก่อน +1

      It's Sol Goodman wrapper at Lua

  • @LucasAlmeida-ef9io
    @LucasAlmeida-ef9io หลายเดือนก่อน +5

    Sol is a great name for a Lua wrapper. It means "sun" in portuguese, and Lua means "moon"

  • @conrad6071
    @conrad6071 หลายเดือนก่อน

    can believe the series updated

  • @clementtarin9936
    @clementtarin9936 หลายเดือนก่อน

    Nice you do video again... 🎉

  • @MrVinicius5000
    @MrVinicius5000 หลายเดือนก่อน

    LOL i was just re-watching this series for some embeding ideas i was having XD

  • @4F6D
    @4F6D หลายเดือนก่อน

    He is back guys!

  • @TurtleKwitty
    @TurtleKwitty หลายเดือนก่อน

    Very interesting library! Just wish you had shown off in that last segment what happens if lua gives in somethign invalid

  • @vgtuyuytv
    @vgtuyuytv หลายเดือนก่อน +2

    sol2 is almost too good to be true
    shoutouts to thePhD

  • @charlesAcmen
    @charlesAcmen หลายเดือนก่อน +1

    Excuse me, i have a question for your previous video about cross platform c++ GUI framework which is called wxwidgets,i do not quite understand the whole rendering principle behind,i mean how can i control my rendering fps?using wxTimer or idleEvent?could you please tell me in detail about it,it really means a lot to me,because i have devoted so much time in investigating this framework including watching your video over and over agagin !!!!!!!!!!!!!!!!!!!!!!

  • @scififan698
    @scififan698 หลายเดือนก่อน +1

    7:00 to print exception.what() to std output, do you have to wrap it into a string? I didn't know that... I would have hoped it already could print a char* just by itself. You live, you learn!!

    • @WatermelonMD
      @WatermelonMD หลายเดือนก่อน +2

      You don't have to. I looked up sol::error::what and it returns const char* which you can print directly to cout. I don't know why he casts it

  • @ondrakavan4119
    @ondrakavan4119 หลายเดือนก่อน

    Great video and I have a question. Is there a way to have code completion in Lua? Like if you create a function in c++ and call it from Lua.

    • @javidx9
      @javidx9  หลายเดือนก่อน

      Thanks! I'm not aware personally of any IDE that would be that sophisticated. It gets tricky because you can effectively create lua things at runtime, so the code completion would be partial at best.

  • @amr3162
    @amr3162 หลายเดือนก่อน

    didn’t realize that part 1 was 5 years ago, and had to scroll forever in the recent videos to find it 😅

  • @uriid1
    @uriid1 หลายเดือนก่อน

    I love lua :)

  • @michaelsherwin4449
    @michaelsherwin4449 14 วันที่ผ่านมา

    Hi Javid, I can't find an example of what I am looking for. I want a C++ engine to run and display a game world. And computer player AI(s) written in a scripting language to be able to query the current game state and then tell the C++ engine what it wants to do. It can be turn based or real time. For example an author can write an AI to play Risk. It can then be an interesting opponent to have in the game or it can be entered in a tournament of other AIs. Or an online RPG can allow people to submit an NPC AI. It could be a villain or maybe 'someone' that can be hired to help the human player. The possibilities are endless and I wonder why it has not been done? Or has it?

  • @TECHN01200
    @TECHN01200 หลายเดือนก่อน

    I'm curious about the &TypeName::fieldName syntax. What does that do?

    • @user-yw5et3os6i
      @user-yw5et3os6i หลายเดือนก่อน +1

      It gives you the offset of the member from the base adress of the struct / class.

  • @adlen01
    @adlen01 หลายเดือนก่อน

    How to fix the compilers bugs of dev c++?

  • @dhiahassen9414
    @dhiahassen9414 14 วันที่ผ่านมา

    I have used kaguya library before fir lua in c++ and it is the best by far, it is header only and has much better api

  • @moose-3379
    @moose-3379 หลายเดือนก่อน

    How close is the community to convincing Javid to use vcpkg? 😁

  • @hudsonator7259
    @hudsonator7259 27 วันที่ผ่านมา

    Wheres ep. 2?

  • @skejeton
    @skejeton หลายเดือนก่อน

    luaJIT is even simpler, you declare function prototype in the lua Script and implement it in C and it will somehow work, i don't know how

  • @japedr
    @japedr หลายเดือนก่อน +1

    28:10 well, technically you are giving it a pointer, not a reference

  • @Maxjoker98
    @Maxjoker98 หลายเดือนก่อน +1

    I've never used Sol in a project(not a C++ guy), but I'M very familiar with the regular Lua C API. But for best performance you should probably avoid non-standard library C function calls like the pest: When using LuaJIT the Lua and standard library functions are incredibly fast to call, since the compiler doesn't need to emit actual ABI calls, it can inline most functionality. Another trick somewhat related to that is using the LuaJIT FFI; Not to call C functions(since it also is slow due to ABI), but rather for it's data types. You can create C types(integers, pointers, arrays etc.), and access to those is really efficient(can be inlined by LuaJIT). My own graphics engine is Lua-only, with optional support for LuaJITs FFI for acceleration. Works really nicely.

    • @j.trades9691
      @j.trades9691 หลายเดือนก่อน

      He gives a pretty good indirect argument _against_ using LuaJIT's FFI at 5:16 -- The FFI (even just C types, though giving access to most standard library functions also opens up its' own can of worms) actually open up a form of attack surface you normally wouldn't be able to achieve with Lua; for example, one could misuse a C pointer by manually setting the value to somewhere within the host binary's stack or heap and start messing around with the data, or even potentially call functions if they're in a vtable somewhere. Offhand, I recall a few cases of this in scripts for Morrowind's Script Extender, where the community hacked in Luajit support; I can't remember the exact name of the mod offhand, but there's one in particular that does some pretty gnarly manual pointer shenanigans to edit base game UI functions.

    • @Maxjoker98
      @Maxjoker98 หลายเดือนก่อน

      @@j.trades9691 While the problem you describe is real, even Lua code "sandboxed" in that way can often be exploited, especially if you allow loading bytecode(which helps loading times) - For me, and most games, that is a non-issue though: Only trusted Lua code is ever run. And you can get better sandboxing with LuaJIT if you desire: Just create a small FFI binding to the Lua C API, and create completely separate and isolated Lua_State(doesn't even have to be LuaJIT).
      I think of LuaJIT as Lua 5.1 + optional C-like language. If you can't do it the Lua way, use the C way. If you can't do it the C way, do it the Lua way.

  • @user-cy1rm5vb7i
    @user-cy1rm5vb7i หลายเดือนก่อน

    btw, why don't you use luajit? It's supposed to be 'much faster' that plain lua. 🤔

  • @averageengineeer
    @averageengineeer หลายเดือนก่อน

    Is the same possible with Python ?

    • @samuelhulme8347
      @samuelhulme8347 หลายเดือนก่อน

      Yes, but I think it’s more complicated to include in your project.

  • @Blackoutfor10days
    @Blackoutfor10days หลายเดือนก่อน +1

    Can you make an operating system like windows 😊

  • @harleyspeedthrust4013
    @harleyspeedthrust4013 หลายเดือนก่อน +1

    better call sol

  • @KeithKazamaFlick
    @KeithKazamaFlick หลายเดือนก่อน

    vimto

  • @sadhappy8860
    @sadhappy8860 หลายเดือนก่อน

    Hello,

  • @joseoncrack
    @joseoncrack หลายเดือนก่อน +2

    Meh, just use C. ;)

  • @marcoswillians4486
    @marcoswillians4486 หลายเดือนก่อน +1

    Acho que essa linguagem foi criada no Brasil. Se não me engano acho que já brinquei com ela, fazendo fases pro Roblox.

    • @LucasAlmeida-ef9io
      @LucasAlmeida-ef9io หลายเดือนก่อน +1

      Foi sim, no Rio de Janeiro
      Curiosidade: é uma das linguagens populares com menos keywords (menos que C e Python)

    • @user-yw5et3os6i
      @user-yw5et3os6i หลายเดือนก่อน +1

      Roblox is using a fork of lua called luau that is faster and safer because it provides sandboxing utilities. Making a lua binding safe is hard.
      It also has an optional type checker that helps you write better code. It also uses this information under the hood to compile to faster byte code.

  • @veronikedearmore1347
    @veronikedearmore1347 29 วันที่ผ่านมา

    🤣 *Promosm*

  • @gsestream
    @gsestream หลายเดือนก่อน

    lambda syntax is not very clear. simple as always is the best. explicit is better than implicit.

  • @wolpumba4099
    @wolpumba4099 หลายเดือนก่อน +2

    *Embedding Lua in C++ with Sol: A Compare and Contrast*
    This video compares and contrasts embedding Lua in C++ with and without the Sol library. Part 1 of the series covered a bare-bones implementation, while this video demonstrates Sol's advantages.
    *Introduction and Setup (**0:00**)*
    * This video is part 3 of a series on embedding Lua in C++.
    * It showcases the Sol library as a superior alternative to the manual approach shown in Part 1.
    * Sol simplifies Lua integration and offers various benefits, including safety features and reduced boilerplate code.
    * The video uses the same Lua script and C++ code from Part 1 for comparison.
    * Setting up Sol involves downloading the library and linking it to your project.
    *Configuring the C++ Environment (**1:48**)*
    * Sol streamlines configuration by handling Lua interaction through its interface.
    * Sol allows explicit selection of Lua libraries to expose to the user, reducing the attack surface.
    * Sol offers header-only inclusion for convenience.
    *Running Lua Scripts (**3:46**)*
    * Sol provides a `safe_script` function to execute Lua scripts with robust error handling and informative messages.
    * This contrasts with the manual approach, which required custom error checking and stack manipulation.
    *Reading Variables (**6:51**)*
    * Sol's `get_or` function simplifies reading variables from Lua scripts with default values and type conversion.
    * Sol also offers `optional` for checking variable existence without throwing exceptions.
    * This approach is safer and more convenient than manually checking the Lua stack.
    *Reading Tables (**11:14**)*
    * Sol allows iterating through Lua tables using C++-style for loops and accessing key-value pairs.
    * Sol objects can be easily converted to desired C++ types.
    * Sol offers direct table indexing for accessing specific values.
    *Calling Lua Functions from C++ (**15:03**)*
    * Sol allows calling Lua functions directly with arguments and automatic return value handling.
    * This eliminates the need for manual stack manipulation and error checking.
    * Sol's `protected_function` provides additional safety by checking function validity before execution.
    *Calling C++ Functions from Lua (**20:17**)*
    * Sol enables injecting C++ functions into the Lua environment using lambdas.
    * This simplifies the process compared to the manual approach of registering functions and managing the stack.
    *Injecting Values and Functions into Lua (**22:35**)*
    * Sol allows creating new Lua variables and functions directly from C++.
    * The `script` function enables executing arbitrary Lua code within the C++ program.
    *Mapping C++ Types to Lua (**23:58**)*
    * Sol's `new_usertype` function facilitates mapping C++ structs to Lua objects with custom constructors and property access.
    * This allows creating and manipulating C++ objects directly from Lua scripts.
    *Using C++ Containers in Lua (**27:45**)*
    * Sol provides bindings for standard C++ containers like vectors, allowing their use within Lua scripts.
    * This enables populating and manipulating C++ containers directly from Lua.
    *Conclusion (**30:15**)*
    * Sol offers a powerful and intuitive way to embed Lua in C++ projects.
    * Its features significantly reduce boilerplate code, improve safety, and enhance flexibility.
    * The video encourages viewers to explore Sol and its capabilities further.
    Disclaimer: i used gemini 1.5 pro to summarize the transcript
    Token count 8,845 / 1,048,576

    • @desertfish74
      @desertfish74 หลายเดือนก่อน

      Summarize?? It basically returned a full transcript

    • @wolpumba4099
      @wolpumba4099 หลายเดือนก่อน

      @@desertfish74 The transcript has 6037 words, the summary 516.