Corrosive Posted January 13, 2015 Share Posted January 13, 2015 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] Link to comment 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 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 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.