Jump to content




How would one make os.loadAPI() in pure Lua?


4 replies to this topic

#1 cyanisaac

  • Members
  • 369 posts
  • LocationSan Diego, CA

Posted 27 July 2015 - 12:27 AM

Hi! I am interested in making a ComputerCraft-like-thing-that-is-actually-in-love2d-which-uses-luajit-so-yeah.

How would one make os.loadAPI() in PURE Lua 5.1?

Thanks!

P.S. not sure if this is the right place to ask but I think it is considering this is the place to ask questions :P

P.S.S. pretty sure how unloadAPI would work, it's just loadAPI I am curious about

Edited by cyanisaac, 27 July 2015 - 12:28 AM.


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 27 July 2015 - 12:45 AM

You can find the source in bios.lua. You'll need an understanding of environment tables to see how it works.

Edited by Bomb Bloke, 27 July 2015 - 12:46 AM.


#3 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 27 July 2015 - 12:47 AM

Replace the second line of the function with something like:

local sName = string.match(_sPath, "([^/\\]+)$")

Replace printError calls with error calls.

#4 cyanisaac

  • Members
  • 369 posts
  • LocationSan Diego, CA

Posted 27 July 2015 - 01:28 AM

Here's my code so far.

My Modified LoadAPI Code

However I get the following message:
"Error: main.lua:37: bad argument #2 to 'loadfile' (string expected, got table)

[c]: main.lua:37: in function 'loadfile'
main.lua:37: in function 'loadAPI'
main.lua:63: in function 'load'
[C]: in function 'xpcall'"

any suggestions?
Yes I am writing this in Love2D.

Edited by cyanisaac, 27 July 2015 - 01:54 AM.


#5 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 27 July 2015 - 03:11 AM

Base it off of the 1.73 version of os.loadAPI, not the 1.74 version.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users