mirror of
https://github.com/bjornbytes/lovr.git
synced 2024-07-02 12:33:52 +00:00
lovr.graphics.newShader accepts Blobs;
This commit is contained in:
parent
f444809f0f
commit
e3b2a4d974
|
@ -1031,15 +1031,21 @@ int l_lovrGraphicsNewModel(lua_State* L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int l_lovrGraphicsNewShader(lua_State* L) {
|
int l_lovrGraphicsNewShader(lua_State* L) {
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 1; i <= 2; i++) {
|
||||||
if (lua_isnoneornil(L, i + 1)) continue;
|
if (lua_isnoneornil(L, i)) continue;
|
||||||
const char* source = luaL_checkstring(L, i + 1);
|
Blob** blob = luax_totype(L, i, Blob);
|
||||||
|
if (blob) {
|
||||||
|
lua_pushlstring(L, (*blob)->data, (*blob)->size);
|
||||||
|
lua_replace(L, i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const char* source = luaL_checkstring(L, i);
|
||||||
if (!lovrFilesystemIsFile(source)) continue;
|
if (!lovrFilesystemIsFile(source)) continue;
|
||||||
size_t bytesRead;
|
size_t bytesRead;
|
||||||
char* contents = lovrFilesystemRead(source, &bytesRead);
|
char* contents = lovrFilesystemRead(source, &bytesRead);
|
||||||
lovrAssert(bytesRead > 0, "Could not read shader from file '%s'", source);
|
lovrAssert(bytesRead > 0, "Could not read shader from file '%s'", source);
|
||||||
lua_pushlstring(L, contents, bytesRead);
|
lua_pushlstring(L, contents, bytesRead);
|
||||||
lua_replace(L, i + 1);
|
lua_replace(L, i);
|
||||||
free(contents);
|
free(contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue