Jump to content

Should I make the Lua API procedural?


Josh
 Share

Recommended Posts

In the next engine, should the Lua API be procedural? I have watched beginners trying to program, and they have NO IDEA what functions are available for an object. A dynamically typed language can't provide a reliable set of OOP style commands because the functions on an object can change. I know we worked hard to make Lua act sort of C++, but is this really desirable or are we just trying to satisfy some obscure pedantic decree?

OO:

local window = CreateWindow()

local context = CreateContext()

local world = CreateWorld()

local camera = CreateCamera()
camera:SetPosition(0,0,-5)

local box = CreateBox()

while window:KeyHit(KEY_ESCAPE)==false do
	box:Turn(0,1,0)
	world:Update()
	world:Render(context)
end

Procedural:

local window = CreateWindow()

local context = CreateContext()

local world = CreateWorld()

local camera = CreateCamera()
SetEntityPosition(camera,0,0,-5)

local box = CreateBox()

while KeyHit(window,KEY_ESCAPE)==false do
	TurnEntity(box,0,1,0)
	UpdateWorld(world)
	RenderWorld(world,context)
end

I know the OO approach should mean less typing, but it might actually mean MORE typing because the intellisense hints for procedural commands would be much more reliable. As soon as you enter "sete..." you have only the entity commands that set a value to choose from, and from there it is just a few arrow key presses to get the one you want.

What do you think?

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

I'm not sure designing an API around how intellisense works makes any sense whatsoever.  The engine is C++ and thus object oriented, there's no reason the scripting language for the engine shouldn't reflect that.  I wouldn't go out of my way to obfuscate it.

At the end of the day you can just provide both, if it really concerns you?  Both of your examples are procedural anyway, one just uses methods/properties and the other has standalone functions, so you're basically talking a style thing -- which should strictly be up to programmer using it, I'd think.

Ultimately you'd need to decide if you want to groom people into a C++ way of thinking, or add the confusion layer of making program flow work a bit differently between your C++ core and your LUA API (for the simplicity sake of super-newbs).  I'd go with the former and tell people to git gud.

Coding for Christ.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...