1. Alexander Ames
  2. LuaWrapper
  3. Issues
Issue #5 resolved

lua_push<T> - incorrect comment

qwer1304 NA
created an issue

The comment at line 245 seems to be incorrect: storage is ALWAYS allocated, rather than using existing storage as in comment.

Thus, a better name would be lua_new<T> consistent with Lua (which has lua_newuserdata, but not lua_pushuserdata)

Comments (5)

  1. Alexander Ames repo owner

    You're correct that the comment it wrong, but you're wrong about the reason. "Storage", in this case does not refer to userdata, it refers to a table that your object uses to store values on itself. For example, I might have a type Widget and do something like this:

    local w = Widget.new()
    w.foo = 100
    

    Even though Widgets don't have any fields named foo, and Widgets are userdata, I can use the index and newindex metamethods to store foo on a separate table which I refer to as a storage table in the code.

    At one point doing luaW_push would create a storage table if one didn't already exist for the object, but I ran into problems getting them cleaned up and so I moved that code to luaW_hold. However, I've since adjusted how stuff works so I should be able to move that logic back to luaW_push where it really belongs. I'll try to get to that some time this weekend, it's not a hard change.

    There already is a luaW_new, which will create a new object of type T, hold it, and push it on to the Lua stack (You could then retrieve it with T* t = luaW_to<T>(L, -1); if you wanted to use it immediately). luaW_push is an appropriate name for this function as it works mostly analogously to other lua_push* functions.

  2. qwer1304 NA reporter

    (Reply via qwer...@hotmail.com):

    Got it, thanx.

    Subject: Re: [alexames/luawrapper] lua_push<T> - incorrect comment (issue #5) From: issues-reply@bitbucket.org To: qwer1304@hotmail.com Date: Fri, 28 Sep 2012 17:31:00 +0000

  3. Log in to comment