0

So recently, I 've implemented lua scripting in my C++ engine, and I made a lua wrapper for pretty much every classes I had (Window, InputHandler, Mesh, Shader, etc...). But now that I'm thinking of it, is it good that I wrapped all my C++ classes into lua classes ? Shouldn't I use lua scripting for more specific things, and write code like window managing in C++ ? Here is a lua sample :

local input = alpha.InputHandler()
local window = alpha.Window(100, 100, 1000, 900, "Hello Gangnam Style !", false, false)

function main()

    repeat
        window:Clear(0.5, 0.5, 0.5, 1)
        window:SwapBuffers()
        input:Update()
    until input:CloseRequested() == true
end 

main()
4
  • It's a shame this question is indeed too broad, and opinion-based, so it's not suited for SO. Here's an opinion however : yep, I think you've gone too far with Lua :p // When you're integrating a scripting language, the initial balance is "Engine in C++, the rest in Lua". For example, you main loop, your physics engine, etc should be C++, while the behaviour of a lever in your platformer is a good candidate for a script. You've struck it perfectly if you can express your scripts entirely without caring about what the engine looks like.
    – Quentin
    Jul 1, 2015 at 8:08
  • Is it beneficial / required to expose class X to Lua? If yes, wrap it, if not, then don't. It's supposed to be a sandbox, with a well-defined scope.
    – user703016
    Jul 1, 2015 at 8:09
  • So, you want us to explain you, why have you done it? =) Actually, its up to you (task you're working on), should you wrap anything in Lua and in what way should you use scripting. If you will update the whole user interface structure and don't want to recompile app every time it happens - your decision will do. Jul 1, 2015 at 8:15
  • No , no ! I would like you to tell me if this is a good way of doing it ! Actually, here is the source code on codereview : codereview.stackexchange.com/questions/95275/…
    – user4807452
    Jul 1, 2015 at 12:18

1 Answer 1

2

It really depends of your needs and the context.

Do you sell the engine? Do you want buyers to access Lua scripting or is it only for debugging/prototyping?

I find it very handy to have everything bind in Lua since I can prototype fast new features. Though it may be a non perennial solution sometime, so for low-level features, I switch back to c++.

If you plan to let end-users use the Lua scripting, you can also sandbox it, providing the users a subset of white-listed functions. http://lua-users.org/wiki/SandBoxes

3
  • 1) No it's gonna be an open source game engine; Yes, i actually want them to isolate the game logic into the script. After reflection, I think that I will leave render stuff to C++, and game logic to lua ( like game loop, input handling ... ) Is it a good idea ?
    – user4807452
    Jul 1, 2015 at 10:44
  • It is a good idea! Though I find it very handy to be able to prototype render stuff in lua too :) Jul 2, 2015 at 7:49
  • Ok ! I agree ! I'll post the link to the github project if you are intrested !
    – user4807452
    Jul 2, 2015 at 7:58