Corrosive Posted January 13, 2015 Share Posted January 13, 2015 (edited) My experience has generally been with JavaScript, PHP, Perl and VB, and the last time I worked with Lua was when I wrote a mod for WoW many many years ago. It's entirely possible I'm missing something obvious. Anyway, while trying to simultaneously figure out Lua and the DS API, I wrote a simple print_r function to use in the console while rooting around. The problem is, whenever I tried calling it, I got bad argument errors. So I made the simplest function I could muster in global space to test: function GLOBAL:test(a_table, a_string, a_misc) print("a_table: " .. type(a_table)) print(a_table) print("a_string: " .. type(a_string)) print(a_string) print("a_misc: " .. type(a_misc)) print(a_misc) endHard to get more simple than that, right?I tried entering this into the console: test_table = GetPlayer() test_string = "Some string." test_misc = {} test(test_table, test_string, test_misc)Here's what pops out every time: a_table: string Some string. a_string: table table: 2E93C090 a_misc: nilObviously this isn't what I'm expecting. The 1st and 2nd argument appear to be swapped, and the third argument is nil when it should be a table. If I do print(a_table/string/misc) or print(type(a_table/string/misc)) from the console I get exactly what I expect, though. What gives? Have I been playing too much DS? Am I starting to lose my mind as well?[edit: formatting] Edited January 13, 2015 by Corrosive Link to comment https://forums.kleientertainment.com/forums/topic/49043-function-argument-insanity-losing-my-mind/ Share on other sites More sharing options...
Developer Kevin Posted January 13, 2015 Developer Share Posted January 13, 2015 Try rewriting your function as: function GLOBAL.test(a_table, a_string, a_misc) The colon that you are currently using gobbles the first parameter as 'self', which is something you usually do when using OO in lua. This stackoverflow post explains it better:http://stackoverflow.com/questions/4911186/difference-between-and-in-lua Link to comment https://forums.kleientertainment.com/forums/topic/49043-function-argument-insanity-losing-my-mind/#findComment-601158 Share on other sites More sharing options...
Corrosive Posted January 13, 2015 Author Share Posted January 13, 2015 Ah jeez, I knew it'd be something dumb! Thanks for saving me another few hours of befuddlement, and for further deepening my love/hate relationship with syntactic sugar! Link to comment https://forums.kleientertainment.com/forums/topic/49043-function-argument-insanity-losing-my-mind/#findComment-601631 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now