Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pci.lua, intel10g.lua: Load a dedicated Lua module for each NIC port.
This is an experiment in Lua coding style. Now device driver modules can be written as if there is only one device to control. The PCI address of this device is known when the module is loaded. This is my current favorite of the three main programming styles that I have seen for using the same driver module for multiple devices: 1. Table-based OO. The discipline of Using `self:foo()` and `self.foo` to access everything that is unique for each device. 2. Closure-based OO. Wrapping the whole driver in a `new()` function and defining `local` variables for everything that is unique for each device. 3. Module-based OO. The module code is specific to one device and no special programming discipline is needed. The module needs to be loaded in a special way and reloaded for each instance. (This is what this commit implements.) Feedback welcome!
- Loading branch information
Showing
2 changed files
with
62 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b44c0fb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How different is invoking
driver.selftest()
vsdriver:selftest()
? From a calling perspective, the difference is the choice of a character. I assume your real point of contention is with the use ofself
in the definition of the module. I understand you feel it is cumbersome, but I guess after years of Python, I've become accustomed toself
(in Python it's even worse as you have to explicitly define that first argument in every function definition!). Aside fromself
, I've been using the regular OO-idiom, but I like the idea of parameterizing therequire
to instantiate an object. Using this method, you could create instances in this manner:The module would then be defined like:
Interesting discussion! Ultimately, it makes no difference to me. I suppose the only benefit to the standard approach is to make it easier for newcomers to Snabb Switch to contribute. If they are existing Lua users, the common idiom may be easier to understand, and if they are not, newbies like myself will simply see the common idiom peppered throughout all of the Lua documentation/books. Having said that though, Lua is sufficiently vague and it encourages one to experiment so it would almost be a disservice if you purposely didn't mix things up!