Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function tblinsert(t, arg1, arg2)
- local key, value;
- -- Make sure we have t and it's a table.
- assert(t and type(t)=="table");
- assert(arg1); -- Make sure we have arg1
- -- Now we work out if we've been given both a key and a value, or just a value.
- -- If we've been given three arguments then arg2 should equal our value. If it is nil then arg1 is our value.
- if arg2 then
- value = arg2;
- key = arg1;
- else
- value = arg1;
- key = #t + 1;
- end
- t[key] = value;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement