Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.48 KB | None | 0 0
  1. function tblinsert(t, arg1, arg2)
  2.     local key, value;
  3.    
  4.     -- Make sure we have t and it's a table.
  5.     assert(t and type(t)=="table");
  6.     assert(arg1); -- Make sure we have arg1
  7.    
  8.     -- Now we work out if we've been given both a key and a value, or just a value.
  9.     -- If we've been given three arguments then arg2 should equal our value. If it is nil then arg1 is our value.
  10.     if arg2 then
  11.         value = arg2;
  12.         key = arg1;
  13.     else
  14.         value = arg1;
  15.         key = #t + 1;
  16.     end
  17.    
  18.     t[key] = value;
  19. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement